users@glassfish.java.net

Re: RE: Problem with JPA and cache

From: <glassfish_at_javadesktop.org>
Date: Tue, 15 Jul 2008 15:38:22 PDT

Manfred, thanks for taking time to take a look. I cannot change the code to use a "merge" because of the Command pattern that is in use. The Commands do not know about each other. Basically in one Command, the first section of code where the Parent is created and persisted and flushed is performed. A totally separate Command uses an ID and "finds" the Parent and performs an update on it. Subsequent Commands "find" the Parent by ID again and add children. None of the individual Commands know about each other and they are independent but in the one case, strung together to perform the desired goal.

I have verified that when the code find the Parent and returns it into "p1", this is in fact the same Object (same memory location) as what is pointed to by "p0". So that part of the persistence cache is working correctly. The problem is not that there are separate Parent objects being accessed. They are equal (=) and in fact when I watch the code in the debugger and see the "serialNumber" set, I see this effecting both "p0" and "p1" which makes it clear that both "p0" and "p1" are pointing at the same object.

Since I have a Cascade = Cascade.ALL annotation, I do not need to persist any of the other entities. The will be persisted when the transaction is committed and in fact this occurs correctly.

Again, this is just a test application that simulates what is happening in my very much larger J2EE application. Also again, the underlying database is correct. In fact, if I shut down my J2EE application and restart and query the "Parent', at that point it will have all of the correct "Child" entities attached.
[Message sent by forum member 'bbergquist' (bbergquist)]

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