-->
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: Session.contains() and NonUniqueObjectException
PostPosted: Thu Aug 02, 2007 5:55 am 
Beginner
Beginner

Joined: Thu Apr 12, 2007 10:38 am
Posts: 22
Hi

When I do a save() on an object that is identified with a compound key, I get

org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session

My main task is to find out when this original object is getting into the session because as far as I know, it's a clean session. So first question: is there an easy way to find out when it went into the session?

Also, for debugging purposes, I'm using this code
Code:
if(getHibernateTemplate().getSessionFactory().getCurrentSession().contains(testObject)) {
log.debug("Already contains this object");
}
getHibernateTemplate().save(test);

I never drop into the log statement, but then the save() statement throws the NUO Exception. How is this possible?

Thanks!


Top
 Profile  
 
 Post subject: Re: Session.contains() and NonUniqueObjectException
PostPosted: Wed Jun 17, 2009 6:07 am 
Newbie

Joined: Wed Jun 17, 2009 6:02 am
Posts: 4
Hi,

sorry for gravedigging, but this problem is still a concern to me and i don't find an answere anywhere.

i'm using a similar construct in my ajax web-application (RAP, OpenSessionInView pattern):

Code:
public void reattach(Object entity) {
    if (!getSession().contains(entity)) {
            getSession().lock(entity, LockMode.NONE);
    }
}


this still throws an NonUniqueObjectException at some occurences. Isn't the contains() method intended to handle this?? why does the contains() method returns false allthough the object seems to be present in the session thus throwing the NUOE?!?

please can anyone help??


greetings,
-ben


Top
 Profile  
 
 Post subject: Re: Session.contains() and NonUniqueObjectException
PostPosted: Wed Jun 24, 2009 10:57 am 
Newbie

Joined: Wed Jun 17, 2009 6:02 am
Posts: 4
hi, is there really no one who can help me?!

i'm using hibernate in my ajax web application (based on the Rich-Ajax-Platform (RAP)). since the application uses a rich GUI, which is quite common i think, i can't tell what the user click next and which operations are executed in which order. it is possible to execute several operations that require a DB transaction in a request-response session so i have to determine in each operation whether the object is already associated to the session. it seems that the contains() method of the session does not work this way. as i stated in the previous post, the contains() method returns false on an entity but if i try so reassociate the entity with the session subsequently i get the NOU exception.

i'm really dependent on such a functionality, does no one has the same or similiar problems?!

thx in advance!

greetings,
-ben


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.