-->
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: org.hibernate.NonUniqueObjectException
PostPosted: Wed Mar 24, 2010 12:09 pm 
Newbie

Joined: Fri Mar 19, 2010 11:10 am
Posts: 4
hi all,

I have this Exception:
org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: [LoginData#]

when I try to save the object User.

Code:
Session = HibernateSessionFactoryMaster.getSessionFactory().openSession();
session.beginTransaction();
session.save(user);
session.getTransaction().commit();
session.close();


My mapping:

Code:
<hibernate-mapping>
<class name="User" table="User" lazy="false">
    <id column="Id" name="Id">
      <generator class="guid"/>
    </id>
    <property name="login"/>
   
    <list cascade="all" lazy="true" name="loginD" table="LoginData">
      <key column="userId"/>
      <list-index column="idx"/>
      <one-to-many class="LoginData"/>
    </list>
</class>

<class name="LoginData" table="LoginData" lazy="false">
    <id column="loginDataId" name="loginDataId" unsaved-value="0">
      <generator class="guid"/>
    </id>
    <property name="login"/>
    <property name="password"/>
    <property name="roleId"/>
  </class>

</hibernate-mapping>


if a save before the object LoginData and then the object User works fine.... but it is necessary with cascade"all" ?

any ideas?

thanks


Top
 Profile  
 
 Post subject: Re: org.hibernate.NonUniqueObjectException
PostPosted: Sat Mar 27, 2010 4:41 am 
Beginner
Beginner

Joined: Wed Jan 07, 2009 7:07 pm
Posts: 26
The exception clearly states that you are trying to associate two objects with same id in the session. Check your equals and hash code() implementation.


Top
 Profile  
 
 Post subject: Re: org.hibernate.NonUniqueObjectException
PostPosted: Mon Mar 29, 2010 9:36 am 
Newbie

Joined: Fri Mar 19, 2010 11:10 am
Posts: 4
thanks for your answer,

That's not the problem, I have @Override the equals and the hashCode methods for both classes, the error is the same:

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

Sound that the session Identifier is not the object id ...

thanks


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.