On Dec 12, 2006, at 6:48 PM, Dain Sundstrom wrote:

Sorry about he subject free email :)

On Dec 12, 2006, at 6:42 PM, Patrick Linskey wrote:

On Dec 12, 2006, at 6:24 PM, Dain Sundstrom wrote:

Does JPA guarantee that only one bean will be activated for a
specific pk per transaction?

Yes.

Specifically, will OpenJPA ever create more that one bean for a
specific Class:PK in a single transaction?

No.

The full story is a little bit more complicated with OpenJPA. JPA guarantees that object equality (==) comparison must pass for two references that point
to the same database record in the same transaction. IOW, however you
navigate to / query for a given record, you'll get back a reference to the
same Java object in a given transaction.

The complication is that in most circumstances, OpenJPA holds weak
references to all objects except ones with unflushed modifications. The guarantee I outlined above still holds, since if you hold a reference to an instance, our weak reference will be maintained as well, and equality tests
will pass. But if you release your reference, the instance may become
garbage-collected, so if you later query for / navigate to the instance, you
might end up with a different object reference.

I bring all this up because it means that OpenJPA does not guarantee that the return value of System.identityHashCode() will be the same for a given record over the course of a transaction. So, be sure that you bear this
restriction in mind if you use an IdentityHashMap or some equivalent
structure.

Very cool.

I maintain that you don't need to concern yourself with this issue. If you hold a strong reference to an instance, it won't ever be replaced by a different one with the same database identity. And if you hold a weak reference, you don't care because when you access it again, you will get the same instance as OpenJPA holds.

Craig

-dain

Craig Russell
Architect, Sun Java Enterprise System http://java.sun.com/products/jdo
408 276-5638 mailto:[EMAIL PROTECTED]
P.S. A good JDO? O, Gasp!

Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to