Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[eclipselink-users] Big problem: QueryException in simple JPA Case

Hi,

JPA fails when I access properties of detached objects. This happens
when the persistence context is new, that means that the objects were
not used before except by the first call to
EntityManager.getReference() that gets them before they leave the
persistence context.

The exception is not thrown with TopLink Essentials. Details of the
exception are below.

I am fully aware that the objects are detached, and that lazily
fetched related objects or properties may not be available in the
detached state. So I fetch and set all related objects in the session
using EntityManager.getReference() so the object graph is complete
when it leaves the transaction.

A possible workaround is to "touch" i.e. get the properties that are
subject to the crashes within the session/transaction. Example:
parentEntity.getChildEntity().getName();

However this workaround is not feasible because it means that I would
have to load the whole database into memory and touch all properties
before it is usable.

I have searched the web for any ideas what I might be missing in the
configuration.

I can reproduce this error in a testcase with JVM setting
-javaagent:eclipselink-2.0.0.jar, and I am getting this problem with
GlassFish V3.0 out of the box.

Any help or hints are highly appreciated.

Many thanks in advance!

Bernard



Details of the exception:

Exception [EclipseLink-6004] (Eclipse Persistence Services -
2.0.0.v20091127-r5931):
org.eclipse.persistence.exceptions.QueryException
Exception Description: The object [...], of class [class ...], with
identity hashcode (System.identityHashCode()) [...], 
is not from this UnitOfWork object space, but the parent session's.
The object was never registered in this UnitOfWork, 
but read from the parent session and related to an object registered
in the UnitOfWork.  Ensure that you are correctly
registering your objects.  If you are still having problems, you can
use the UnitOfWork.validateObjectSpace() method to 
help debug where the error occurred.  For more information, see the
manual or FAQ.
Query: ReadObjectQuery(referenceClass=... sql="SELECT ID, .., ... FROM
... WHERE (ID = ?)")
        at
org.eclipse.persistence.exceptions.QueryException.backupCloneIsOriginalFromParent(QueryException.java:253)



Back to the top