Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [eclipselink-users] NullPointerException in 2.3.2 while persisting

Hi Laird,

  The stack is the same as this bug:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=391036

  Is there any chance one of the involved entities is not listed as part of the persistence unit?

-Tom

On 29/08/2013 9:41 AM, Laird Nelson wrote:
Hello; I'm receiving a NullPointerException from EclipseLink 2.3.2 (version that ships with GlassFish 3.1.2.2) while persisting an object (a PostalAddress).

The object has a @ManyToOne with no explicit cascade instructions on it (a PostalAddressType).  The related object is (to my knowledge) not part of the persistence context (it was apparently retrieved in a non-transactional method, so is a detached object).

So:

P (managed) --> PAT (detached)
em.persist(P);
em.flush(); // throws NullPointerException

The relevant stack snippet is:

java.lang.NullPointerException
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.checkForUnregisteredExistingObject(UnitOfWorkImpl.java:752)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.discoverAndPersistUnregisteredNewObjects(UnitOfWorkImpl.java:4135)
at org.eclipse.persistence.mappings.ObjectReferenceMapping.cascadeDiscoverAndPersistUnregisteredNewObjects(ObjectReferenceMapping.java:906)
at org.eclipse.persistence.mappings.ObjectReferenceMapping.cascadeDiscoverAndPersistUnregisteredNewObjects(ObjectReferenceMapping.java:884)
at org.eclipse.persistence.internal.descriptors.ObjectBuilder.cascadeDiscoverAndPersistUnregisteredNewObjects(ObjectBuilder.java:1917)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.discoverAndPersistUnregisteredNewObjects(UnitOfWorkImpl.java:4148)
at org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.discoverUnregisteredNewObjects(RepeatableWriteUnitOfWork.java:299)
at org.eclipse.persistence.internal.sessions.UnitOfWorkImpl.calculateChanges(UnitOfWorkImpl.java:702)
at org.eclipse.persistence.internal.sessions.RepeatableWriteUnitOfWork.writeChanges(RepeatableWriteUnitOfWork.java:433)
at org.eclipse.persistence.internal.jpa.EntityManagerImpl.flush(EntityManagerImpl.java:780)
at com.sun.enterprise.container.common.impl.EntityManagerWrapper.flush(EntityManagerWrapper.java:418)

The first thing I would like to understand is: should this operation work at all?  The specification, section 3.2.2 seems to indicate that it should--the detached object to which my PostalAddress points is detached, true, but there's no explicit cascade information.

The second thing I would like to understand is how to work around this.  :-)  I presume the easiest way would be to do a (unnecessary) find on the detached object (the PostalAddressType) so that it enters the persistence context--I'd hope that would be enough to bypass the code path that routes through checkForUnregisteredExistingObject().

Best,
Laird

--
http://about.me/lairdnelson


_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users


Back to the top