Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EclipseLink » java.lang.NullPointerException: when OrderedListContainerPolicy.updateChangeRecordForSelfMerge(...)
java.lang.NullPointerException: when OrderedListContainerPolicy.updateChangeRecordForSelfMerge(...) [message #1729139] Mon, 11 April 2016 13:23 Go to next message
Juan Llado is currently offline Juan LladoFriend
Messages: 3
Registered: April 2016
Junior Member
Hi,

Sometimes (in live servers) we are getting the following exception when we try to do a merge:
Caused by: java.lang.NullPointerException: null                                                                                                                                                     [918/1871]
        at org.eclipse.persistence.internal.queries.OrderedListContainerPolicy.updateChangeRecordForSelfMerge(OrderedListContainerPolicy.java:712) ~[eclipselink.jar:2.6.2.v20151217-774c696]
        at org.eclipse.persistence.mappings.CollectionMapping.updateChangeRecordForSelfMerge(CollectionMapping.java:2135) ~[eclipselink.jar:2.6.2.v20151217-774c696]
        at org.eclipse.persistence.descriptors.changetracking.AttributeChangeTrackingPolicy.updateListenerForSelfMerge(AttributeChangeTrackingPolicy.java:131) ~[eclipselink.jar:2.6.2.v20151217-774c696]
        at org.eclipse.persistence.mappings.CollectionMapping.mergeIntoObject(CollectionMapping.java:1642) ~[eclipselink.jar:2.6.2.v20151217-774c696]
        at org.eclipse.persistence.internal.descriptors.ObjectBuilder.mergeIntoObject(ObjectBuilder.java:4133) ~[eclipselink.jar:2.6.2.v20151217-774c696]
        at org.eclipse.persistence.internal.sessions.MergeManager.mergeChangesOfCloneIntoWorkingCopy(MergeManager.java:594) ~[eclipselink.jar:2.6.2.v20151217-774c696]
        at org.eclipse.persistence.internal.sessions.MergeManager.mergeChanges(MergeManager.java:313) ~[eclipselink.jar:2.6.2.v20151217-774c696]
        at org.eclipse.persistence.mappings.CollectionMapping.mergeIntoObject(CollectionMapping.java:1638) ~[eclipselink.jar:2.6.2.v20151217-774c696]
        at org.eclipse.persistence.internal.descriptors.ObjectBuilder.mergeIntoObject(ObjectBuilder.java:4133) ~[eclipselink.jar:2.6.2.v20151217-774c696]
        at org.eclipse.persistence.internal.sessions.MergeManager.mergeChangesOfCloneIntoWorkingCopy(MergeManager.java:594) ~[eclipselink.jar:2.6.2.v20151217-774c696]
        at org.eclipse.persistence.internal.sessions.MergeManager.mergeChanges(MergeManager.java:313) ~[eclipselink.jar:2.6.2.v20151217-774c696]
        at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.mergeCloneWithReferences(UnitOfWorkImpl.java:3521) ~[eclipselink.jar:2.6.2.v20151217-774c696]
        at org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.mergeCloneWithReferences(RepeatableWriteUnitOfWork.java:387) ~[eclipselink.jar:2.6.2.v20151217-774c696]
        at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.mergeCloneWithReferences(UnitOfWorkImpl.java:3481) ~[eclipselink.jar:2.6.2.v20151217-774c696]
        at org.eclipse.persistence.internal.jpa.EntityManagerImpl.mergeInternal(EntityManagerImpl.java:553) ~[eclipselink.jar:2.6.2.v20151217-774c696]
        at org.eclipse.persistence.internal.jpa.EntityManagerImpl.merge(EntityManagerImpl.java:530) ~[eclipselink.jar:2.6.2.v20151217-774c696]
        at org.apache.openejb.persistence.JtaEntityManager.merge(JtaEntityManager.java:202) ~[openejb-core-7.0.0-M2.jar:7.0.0-M2]


If we restart the server, the problem dissapear...

Is it a bug?

It would be great if when Eclipselink retrieves a null record from getChangesForAttributeNamed method, then it throws an exception or log some message...

Any idea of what is the problem?

We are using Eclipselink 2.6.2 with Tomee 7.0.0-M2 (it also happened with previous versions of Tomee).

Thanks!!
Re: java.lang.NullPointerException: when OrderedListContainerPolicy.updateChangeRecordForSelfMerge(. [message #1729295 is a reply to message #1729139] Tue, 12 April 2016 16:39 Go to previous messageGo to next message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1342
Registered: July 2009
Senior Member
The code suggests you have an unmanaged instance added to the entity's collection that doesn't have an entry of it being added in the attribute change listener. More debugging would be required to see how this situation occurred, such as inspecting the entity at the time of the exception.
Re: java.lang.NullPointerException: when OrderedListContainerPolicy.updateChangeRecordForSelfMerge(. [message #1729462 is a reply to message #1729295] Thu, 14 April 2016 10:16 Go to previous messageGo to next message
Juan Llado is currently offline Juan LladoFriend
Messages: 3
Registered: April 2016
Junior Member
Finally, I've reproduced the error.

It happens when I merge an entity which is into a OneToMany attribute of other entity. For example, I have a Trip (fetched from database) that it has a travellers attribute (a List<Traveller> with @OneToMany(cascade = CascadeType.ALL). So, if I execute the following:
Trip trip = entityManager.find(Trip.class, "123455");
Traveller traveller = trip.getTravellers().get(0);
traveller.setName("WTF!");
entityManager.merge(traveller);
traveller.setId("WTF-1");
entityManager.merge(trip);


Then I get the exception:
Caused by: java.lang.NullPointerException: null                                                                                                                                                     [918/1871]
        at org.eclipse.persistence.internal.queries.OrderedListContainerPolicy.updateChangeRecordForSelfMerge(OrderedListContainerPolicy.java:712) ~[eclipselink.jar:2.6.2.v20151217-774c696]


Probably change the id of a persisted entity, it's not a good idea. But I think EclipseLink has to take control of the situation. Better than letting throw a NullPointerException. I really prefer a IllegalStateException with a proper message.

Maybe I can report it as a bug.

Thanks!

[Updated on: Thu, 14 April 2016 10:17]

Report message to a moderator

Re: java.lang.NullPointerException: when OrderedListContainerPolicy.updateChangeRecordForSelfMerge(. [message #1729499 is a reply to message #1729462] Thu, 14 April 2016 18:23 Go to previous message
Chris Delahunt is currently offline Chris DelahuntFriend
Messages: 1342
Registered: July 2009
Senior Member
Unfortunately, there are any number of issues with changing a primary key in entities where caching is involved, and throwing appropriate errors may not be possible for all cases. Filling a bug sounds like a great idea, as fixing NPEs always helps, and it gives another point of reference if someone is searching with the same symptoms and doesn't find this forum post.

Best Regards,
Chris
Previous Topic:Validation on preUpdate checks unchanged entities
Next Topic:Problem when try to use @XmlInverseReference where reference is on abstract class
Goto Forum:
  


Current Time: Thu Apr 09 21:27:22 GMT 2020

Powered by FUDForum. Page generated in 0.07321 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top