-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Should two references to same object work with Hibernate?
PostPosted: Tue Feb 21, 2006 5:35 am 
Newbie

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!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.