Skip to main content



      Home
Home » Eclipse Projects » EclipseLink » java.lang.NullPointerException: when OrderedListContainerPolicy.updateChangeRecordForSelfMerge(...)
java.lang.NullPointerException: when OrderedListContainerPolicy.updateChangeRecordForSelfMerge(...) [message #1729139] Mon, 11 April 2016 09:23 Go to next message
Eclipse UserFriend
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 12:39 Go to previous messageGo to next message
Eclipse UserFriend
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 06:16 Go to previous messageGo to next message
Eclipse UserFriend
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 06:17] by Moderator

Re: java.lang.NullPointerException: when OrderedListContainerPolicy.updateChangeRecordForSelfMerge(. [message #1729499 is a reply to message #1729462] Thu, 14 April 2016 14:23 Go to previous message
Eclipse UserFriend
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: Sat Jul 12 02:07:07 EDT 2025

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

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

Back to the top