Uploaded image for project: 'Spring Data JPA'
  1. Spring Data JPA
  2. DATAJPA-940

java.lang.NullPointerException due to converter

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Invalid
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None

      Description

      java.lang.NullPointerException
      	at org.hibernate.type.AbstractStandardBasicType.compare(AbstractStandardBasicType.java:225)
      	at org.hibernate.type.ComponentType.compare(ComponentType.java:226)
      	at org.hibernate.action.internal.EntityAction.compareTo(EntityAction.java:171)
      	at org.hibernate.engine.spi.ExecutableList.add(ExecutableList.java:222)
      	at org.hibernate.engine.spi.ActionQueue.addAction(ActionQueue.java:225)
      	at org.hibernate.event.internal.DefaultDeleteEventListener.deleteEntity(DefaultDeleteEventListener.java:299)
      	at org.hibernate.event.internal.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:160)
      	at org.hibernate.internal.SessionImpl.fireDelete(SessionImpl.java:965)
      	at org.hibernate.internal.SessionImpl.delete(SessionImpl.java:909)
      	at org.hibernate.engine.spi.CascadingActions$1.cascade(CascadingActions.java:74)
      	at org.hibernate.engine.internal.Cascade.cascadeToOne(Cascade.java:350)
      	at org.hibernate.engine.internal.Cascade.cascadeAssociation(Cascade.java:293)
      	at org.hibernate.engine.internal.Cascade.cascadeProperty(Cascade.java:161)
      	at org.hibernate.engine.internal.Cascade.cascadeCollectionElements(Cascade.java:379)
      	at org.hibernate.engine.internal.Cascade.cascadeCollection(Cascade.java:319)
      	at org.hibernate.engine.internal.Cascade.cascadeAssociation(Cascade.java:296)
      	at org.hibernate.engine.internal.Cascade.cascadeProperty(Cascade.java:161)
      	at org.hibernate.engine.internal.Cascade.cascade(Cascade.java:118)
      	at org.hibernate.event.internal.DefaultDeleteEventListener.cascadeBeforeDelete(DefaultDeleteEventListener.java:353)
      	at org.hibernate.event.internal.DefaultDeleteEventListener.deleteEntity(DefaultDeleteEventListener.java:275)
      	at org.hibernate.event.internal.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:160)
      	at org.hibernate.event.internal.DefaultDeleteEventListener.onDelete(DefaultDeleteEventListener.java:73)
      	at org.hibernate.internal.SessionImpl.fireDelete(SessionImpl.java:956)
      	at org.hibernate.internal.SessionImpl.delete(SessionImpl.java:896)
      	at org.hibernate.jpa.spi.AbstractEntityManagerImpl.remove(AbstractEntityManagerImpl.java:1214)
      	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      

        Activity

        Hide
        olivergierke Oliver Gierke added a comment -

        This is coming from Hibernate. Have you thought about filing an issue in their bug tracker?

        Show
        olivergierke Oliver Gierke added a comment - This is coming from Hibernate. Have you thought about filing an issue in their bug tracker?
        Hide
        syam.elakapalli shyam added a comment - - edited

        I have abstract class and 3 implementation classes.I wrote converter like below,

        public class TaskConverter implements AttributeConverter<TaskType, String> {
         
        	@Override
        	public String convertToDatabaseColumn(TaskType attribute) {
        		if (attribute instanceof ChildTaskType1) {
        			return "TASK1";
        		} else if (attribute instanceof ChildTaskType2) {
        			return "TASK2";
        		} else if (attribute instanceof ChildTaskType3) {
        			return "TASK3";
        		}
        		return null;
        	}
         
        	@Override
        	public TaskType convertToEntityAttribute(String dbData) {
        		if ("TASK1".equals(dbData)) {
        			return new TaskType1();
        		} else if ("TASK2".equals(dbData)) {
        			return new TaskType2();
        		} else if ("TASK3".equals(dbData)) {
        			return new TaskType3();
        		}
        		return null;
        	}
         
        }
        

        Show
        syam.elakapalli shyam added a comment - - edited I have abstract class and 3 implementation classes.I wrote converter like below, public class TaskConverter implements AttributeConverter<TaskType, String> {   @Override public String convertToDatabaseColumn(TaskType attribute) { if (attribute instanceof ChildTaskType1) { return "TASK1" ; } else if (attribute instanceof ChildTaskType2) { return "TASK2" ; } else if (attribute instanceof ChildTaskType3) { return "TASK3" ; } return null ; }   @Override public TaskType convertToEntityAttribute(String dbData) { if ( "TASK1" .equals(dbData)) { return new TaskType1(); } else if ( "TASK2" .equals(dbData)) { return new TaskType2(); } else if ( "TASK3" .equals(dbData)) { return new TaskType3(); } return null ; }   }
        Hide
        olivergierke Oliver Gierke added a comment -

        That's fine, but don't deal with that code, Hibernate does. Please file a ticket with Hibernate.

        Show
        olivergierke Oliver Gierke added a comment - That's fine, but don't deal with that code, Hibernate does. Please file a ticket with Hibernate.
        Hide
        syam.elakapalli shyam added a comment -

        Oliver Gierke Thanks,

        Show
        syam.elakapalli shyam added a comment - Oliver Gierke Thanks,
        Hide
        syam.elakapalli shyam added a comment -

        Oliver Gierke Is there any equivalent annotation for @Type in spring data jpa.

        @Type(type = "com.TaskType", parameters = {
                    @Parameter(name = "TASK1", value = "com.TaskType1"),
                    @Parameter(name = "TASK2", value = "com.TaskType2"),
                    @Parameter(name = "TASK3", value = "com..TaskType3")
                })
                @Access(value = AccessType.FIELD)
                private CustomerTaskType taskType;
        

        public class TaskType
            implements ParameterizedType, UserType, Serializable{
        .....
        }
        

        public class TaskType1 extends CustomerTaskType {
        ...
        }
         
        public class TaskType2 extends CustomerTaskType {
        ...
        }
         
        public class TaskType3 extends CustomerTaskType {
        ...
        }
        

        Show
        syam.elakapalli shyam added a comment - Oliver Gierke Is there any equivalent annotation for @Type in spring data jpa. @Type (type = "com.TaskType" , parameters = { @Parameter (name = "TASK1" , value = "com.TaskType1" ), @Parameter (name = "TASK2" , value = "com.TaskType2" ), @Parameter (name = "TASK3" , value = "com..TaskType3" ) }) @Access (value = AccessType.FIELD) private CustomerTaskType taskType; public class TaskType implements ParameterizedType, UserType, Serializable{ ..... } public class TaskType1 extends CustomerTaskType { ... }   public class TaskType2 extends CustomerTaskType { ... }   public class TaskType3 extends CustomerTaskType { ... }
        Hide
        olivergierke Oliver Gierke added a comment -

        This is not a discussion forum. Please — for the third time — for JPA questions, consult StackOverflow or file tickets with your persistence provider.

        Show
        olivergierke Oliver Gierke added a comment - This is not a discussion forum. Please — for the third time — for JPA questions, consult StackOverflow or file tickets with your persistence provider.

          People

          • Assignee:
            olivergierke Oliver Gierke
            Reporter:
            syam.elakapalli shyam
            Last updater:
            Oliver Gierke
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: