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.  [ 2 posts ] 
Author Message
 Post subject: Separate sessions causing NonUniqueObjectException
PostPosted: Wed Nov 09, 2005 7:29 pm 
Expert
Expert

Joined: Fri Oct 28, 2005 5:38 pm
Posts: 390
Location: Cedarburg, WI
I have a situation with Windows Forms where one window creates a session, queries some objects, then passes some of the objects to a 2nd window that manipulates the 1st window's objects properties. In particular, the 2nd window creates its own session to query objects (since it knows nothing of the 1st window's session), and assigns objects it queries to the properties of passed-in objects.

Back at the 1st window, if I try to flush the changes on the 1st session, if the 1st session had already queried the same entity (same ID) that was separately queried in the 2nd window and assigned to the 1st window's object, I get this exception:

Code:
NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [i]keyValue[/i], of class: [i]className[/i]


In the 2nd window, how could I possibly know that the passed-in object, to which I'm assigning a property with a newly-queried object, was queried in a different session, and that earlier session had also queried the same ID I just queried and assigned?

Do I have to pass sessions around too, and reuse the same session to avoid this? Or how could I tell the 1st session that the object I assigned that came from another session should replace any object with the same ID in its cache?[/i]


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 09, 2005 7:54 pm 
Newbie

Joined: Thu Oct 20, 2005 5:17 pm
Posts: 19
It sounds like you have multiple sessions that are remaining open. It is recommended that you only keep a session open until you have finished an application transaction, then close it.


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

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.