-->
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.  [ 3 posts ] 
Author Message
 Post subject: NonUniqueObjectException
PostPosted: Fri Sep 02, 2005 8:18 am 
Newbie

Joined: Thu Feb 03, 2005 3:51 pm
Posts: 7
Hibernate version: 2.1.7c

Hi,

I need help with NonUniqueObjectException. I´m getting two instances of the same java class with the same identify. But I think that hibernate showd give me the same object reference because I´m working with the same session.

I´m using spring to manager the session.

If I try to query the same record twice I got two diferent objects. And If I try to insert I will get "NonUniqueObjectException".

What I have to do to query the same record more than one time and always get the same object reference;

_________________
Moacir Cardoso
"With no walls and fences on linux who need Windows and Gates"


Top
 Profile  
 
 Post subject: Re: NonUniqueObjectException
PostPosted: Fri Sep 02, 2005 8:36 am 
Expert
Expert

Joined: Mon Feb 14, 2005 12:32 pm
Posts: 609
Location: Atlanta, GA - USA
Very strange as there's another posting right now where they want two differnt objects and are getting the same one. http://forum.hibernate.org/viewtopic.php?t=947123

Are you certain you're using the same session and the first object isn't being evicted somehow ?

_________________
Preston

Please don't forget to give credit if/when you get helpful information.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 02, 2005 8:49 am 
Pro
Pro

Joined: Fri Sep 02, 2005 4:21 am
Posts: 206
Location: Vienna
Hi,

If you're using Spring and don't open a transaction, you'll have a separate Session for every query.

You'll therefore get another instance each time you call the same finder.

One (not so) simple solution is therefore to work within a (Spring) transaction - but, depending on your use case, there may be better solutions.

Erik


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.