-->
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: org.hibernate.NonUniqueObjectException
PostPosted: Thu Apr 06, 2006 4:19 pm 
Newbie

Joined: Thu Apr 06, 2006 4:04 pm
Posts: 9
Hi,

I am getting org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: when i try to load the same object again.

My code looks like below:

public XXX getXXX(String y)
{
XXX theXXX = new XXX ();
session.load(theXXX , y);
return theXXX;
}


this is returning error when i call getXXX("example") two times.
In my application i need to call this method with the same argument two times. How can I do this? Can anybody help me?

Thanks


Top
 Profile  
 
 Post subject: answering my own question
PostPosted: Thu Apr 06, 2006 5:13 pm 
Newbie

Joined: Thu Apr 06, 2006 4:04 pm
Posts: 9
I rectified this as follows:

public XXX getXXX(String y) {
XXX theXXX = new XXX ();
theXXX =(XXX )session.get(XXX .class, y);
if (theXXX == null)
{
session.load(theXXX ,y);

}
return theXXX ;
}


Here I am checking whether the object is already in the session, if not i am loading it.

We can also do like this

public XXX getXXX(String y) {
XXX theXXX = null;
session.load(XXX.class ,y); return theXXX ;
}



Hope this might be helpful for anyone.


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.