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