users@glassfish.java.net

Desparately need help with JPA (Toplink) cache problems

From: <glassfish_at_javadesktop.org>
Date: Thu, 24 Jul 2008 11:12:36 PDT

I've been battleing this problem for a long time. The problem that I am seeing is that the Toplink cache is becoming inconsistent. My code has a parent->child entity bidirectional relationship (and yes I wire up both sides correctly) and when I remove a child entity, in a later transaction, the system the parent entity with the child entity that I removed still attached in the cache. I've attached a snippet of the log.

Thread#19 is in one client transaction. It is going to remove an entity called Chassis9145ConfigSet with ID=428. At the log entry with time "2008-07-24T12:04:30.125-0400", Toplink reports a that the remove operation has been performed. At "2008-07-24T12:04:30.125-0400" the SQL to delete the entity is echoed out by toplink. At time "2008-07-24T12:04:30.375-0400", Toplink echos that it has "Unregistered the object....[id=428]". At time "2008-07-24T12:04:30.656-0400", Toplink echos out that the transaction "status=COMMITTED" so this transaction is complete.

At time "2008-07-24T12:04:30.656-0400", Thread#19 is active again, and Toplink echos a "Execute query ReadObjectQuery" and then at time "2008-07-24T12:04:32.359-0400", Toplink echos "Register the exiting object ...[id=428]". THIS IS THE ENTITY THAT WAS EARLIER REMOVED!

Later the code will try to remove this entity again at time "2008-07-24T12:04:32.468-0400" at which point there is a database exception.

Toplink itself spits out that it is "Unregistering" the object, but later it registers the existing object?

The problem seems to occur quite readily when I have another client that is accessing the same parent entity at the same time that this transaction is going on. It is as if the parent object that Toplink finds in the cache is not the same one that had the child entity removed but rather a different object.

One interesting thing that I just thought of was that I am using the @Version and optimistic locking but when I remove the child entity, I never see the parent entity rewritten to the database with its "version" updated. Because the relationship is owned by the parent and uses a "mappedBy" annotation parameter, I'm not sure if the version column should be updated or not.

But for some reason, the cache either has a different object, with the child entity still attached.

Any help trying to debug this problem will be greatly appreciated!

Brett
[Message sent by forum member 'bbergquist' (bbergquist)]

http://forums.java.net/jive/thread.jspa?messageID=289133