Joined: Wed Aug 03, 2005 11:04 am Posts: 10
|
Hibernate version:
3.1.2
General description:
Let's say we have a class "Person" that has two properties/associations "tennisPartner" and "bestFriend".
We also have two classes "Friend" and "CloseFriend". CloseFriend extends Friend.
The types of the Person-properties are Friend for "tennisPartner" and CloseFriend for "bestFriend". Both associations include "lock" in their cascade rules.
Now we instantiate a CloseFriend object "Mr.Friend" and assign the same object to both properties "tennisPartner" and "bestFriend" of a Person object "Mr.X".
If we now lock (LockMode.NONE) the detached Mr.X to reattach it to the session the BestFriend object Mr.Friend should be locked over the cascade rule as well.
Now we get an NonUniqueObjectException: "a different object with the same identifier value was already associated with the session".
The problem is, that Mr.Friend has been locked over tennisPartner already. If now the object associated as bestFriend is tried to lock it is the same object: Mr.Friend. But the default DefaultLockEventListener fails to retrieve the already locked element from the PersistenceContext (namely the IdentityMap entityEntries). So Hibernate tries to lock the same object again and checkUniqueness fails.
Should this scenario work or not?
Thanks!
|
|