Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » NullPointerException in class ObjectReferenceMapping
NullPointerException in class ObjectReferenceMapping [message #552492] Thu, 12 August 2010 07:35 Go to next message
Mikael Nousiainen is currently offline Mikael Nousiainen
Messages: 7
Registered: August 2010
Junior Member
I get a NullPointerException when calling a setter setTargetGroup() in a detached entity (the transaction has already been committed and closed). I'm using EclipseLink 2.1.0 in GlassFish 3.0.1 with MySQL 5 database.

The entity is called SmsPushActivity and the field is defined as follows:


@Entity
@Table(name = "ACTIVITY_SMS")
@DiscriminatorValue(ActivityType.VALUE_SMS)
public class SmsPushActivity extends ActivityBase {
  private static final long serialVersionUID = 1L;

  @ManyToOne(optional = false, fetch = FetchType.EAGER)
  @JoinColumn(name = "TARGET_GROUP_ID", nullable = false)
  private TargetGroupBase targetGroup;

...
 
 @Override
  public TargetGroupBase getTargetGroup() {
    return targetGroup;
  }

  @Override
  public void setTargetGroup(TargetGroupBase targetGroup) {
    this.targetGroup = targetGroup;
  }


}

@Entity
@Table(name = "ACTIVITY")
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorColumn(discriminatorType = DiscriminatorType.STRING, name = "TYPE", length = 32)
public class ActivityBase extends AbstractNamedDescribableDataObject {

...

}



The exception stack trace:

java.lang.NullPointerException: null
        at org.eclipse.persistence.mappings.ObjectReferenceMapping.setNewValueInChangeRecord(ObjectReferenceMapping.java:186) ~[org.eclipse.persistence.core_2.1.0.v20100614-r7608.jar:2.1.0.v20100614-r7608]
        at org.eclipse.persistence.mappings.ObjectReferenceMapping.internalBuildChangeRecord(ObjectReferenceMapping.java:175) ~[org.eclipse.persistence.core_2.1.0.v20100614-r7608.jar:2.1.0.v20100614-r7608]
        at org.eclipse.persistence.mappings.ObjectReferenceMapping.updateChangeRecord(ObjectReferenceMapping.java:1263) ~[org.eclipse.persistence.core_2.1.0.v20100614-r7608.jar:2.1.0.v20100614-r7608]
        at org.eclipse.persistence.internal.descriptors.changetracking.AttributeChangeListener.internalPropertyChange(AttributeChangeListener.java:149) ~[org.eclipse.persistence.core_2.1.0.v20100614-r7608.jar:2.1.0.v20100614-r7608]
        at org.eclipse.persistence.internal.descriptors.changetracking.AttributeChangeListener.propertyChange(AttributeChangeListener.java:111) ~[org.eclipse.persistence.core_2.1.0.v20100614-r7608.jar:2.1.0.v20100614-r7608]
        at com.moremr.wire.data.AbstractDataObject._persistence_propertyChange(AbstractDataObject.java) ~[wire-core-1.0-SNAPSHOT.jar:na]
        at com.moremr.papa.activity.da.data.SmsPushActivity._persistence_set_targetGroup(SmsPushActivity.java) ~[papa-data-1.0-SNAPSHOT.jar:na]
        at com.moremr.papa.activity.da.data.SmsPushActivity.setTargetGroup(SmsPushActivity.java:63) ~[papa-data-1.0-SNAPSHOT.jar:na]

Re: NullPointerException in class ObjectReferenceMapping [message #552534 is a reply to message #552492] Thu, 12 August 2010 10:47 Go to previous messageGo to next message
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

The error seems to be occurring because there is no descriptor for the type you are setting the targetGroup to.

What are you setting the targetGroup to and how is the TargetGroupBase mapped?

The error is occurring from the weaved change tracking code. You could avoid the error by disabling weaving of change tracking, or detaching the object by casting it to ChangeTracker and calling _persistence_setPropertyChangeListener(null).



James : Wiki : Book : Blog : Twitter
Re: NullPointerException in class ObjectReferenceMapping [message #552665 is a reply to message #552534] Fri, 13 August 2010 02:11 Go to previous messageGo to next message
Mikael Nousiainen is currently offline Mikael Nousiainen
Messages: 7
Registered: August 2010
Junior Member
Strange. I thought that the all objects would automatically become detached (even from change tracking) after the transaction they've been used in has been committed or rolled back. I'm using Spring 3 to manage transactions in GlassFish v3 and the (read-only) transaction is completed in a separate service layer bean long before the setTargetGroup() setter is called.

Anyway, here's the mapping for TargetGroup. I'm actually setting the relation to a TypeinTargetGroup as I have more than one target group subclass. Could this be the problem, as the mapping in SmsPushActivity (naturally) expects the base class TargetGroupBase ?

@Entity
@Table(name = "TARGET_GROUP_TYPEIN")
@DiscriminatorValue(TargetGroupType.VALUE_TYPEIN)
public class TypeinTargetGroup extends TargetGroupBase {

....
}


@Entity
@Table(name = "TARGET_GROUP")
@Inheritance(strategy = InheritanceType.JOINED)
@DiscriminatorColumn(discriminatorType = DiscriminatorType.STRING, name = "TYPE", length = 32)
public class TargetGroupBase extends AbstractNamedDescribableDataObject
implements TargetGroup {

  ...
}
Re: NullPointerException in class ObjectReferenceMapping [message #554630 is a reply to message #552665] Mon, 23 August 2010 14:57 Go to previous messageGo to next message
James Sutherland is currently offline James Sutherland
Messages: 1939
Registered: July 2009
Location: Ottawa, Canada
Senior Member

Please log a bug for this issue.

There is an option in EclipseLink to allow using the superclass descriptor for a subclass. This can be set for inherited descriptors using,

descriptor.getInheritancePolicy().setDescribesNonPersistentS ubclasses(true)

But if you are not using inheritance this will not work. This should probably be configurable for any descriptor or for the whole persistence unit.

Another workaround would be to map this other subclass.


James : Wiki : Book : Blog : Twitter
Re: NullPointerException in class ObjectReferenceMapping [message #554730 is a reply to message #552492] Tue, 24 August 2010 05:33 Go to previous messageGo to next message
Mikael Nousiainen is currently offline Mikael Nousiainen
Messages: 7
Registered: August 2010
Junior Member
I filed this as a bug: https://bugs.eclipse.org/bugs/show_bug.cgi?id=323471

Can you be more specific on the workaround? What do you mean with "mapping the other subclass"? And how would I get access to the class descriptor you're talking about?
Re: NullPointerException in class ObjectReferenceMapping [message #554887 is a reply to message #554630] Tue, 24 August 2010 11:49 Go to previous message
Mikael Nousiainen is currently offline Mikael Nousiainen
Messages: 7
Registered: August 2010
Junior Member
I was already constructing a simple test case for this "bug" when I noticed that I was actually passing a *proxied* object (constructed using CGLIB) to the setter setTargetGroup(), which caused the NullPointerException as EclipseLink naturally did not recognize the proxied version of the class.

So the bug is indeed invalid and the problem is solved.
Previous Topic:Problem with column data type when using Converters
Next Topic:Oracle Outer Join syntax
Goto Forum:
  


Current Time: Wed Jul 23 18:15:01 EDT 2014

Powered by FUDForum. Page generated in 0.02212 seconds