> 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.

-Patrick
_______________________________________________________________________
Notice:  This email message, together with any attachments, may contain
information  of  BEA Systems,  Inc.,  its subsidiaries  and  affiliated
entities,  that may be confidential,  proprietary,  copyrighted  and/or
legally privileged, and is intended solely for the use of the individual
or entity named in this message. If you are not the intended recipient,
and have received this message in error, please immediately return this
by email and then delete it.

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

Reply via email to