-->
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.  [ 1 post ] 
Author Message
 Post subject: NonUniqueObjectException problem
PostPosted: Thu Jun 17, 2004 8:29 am 
Beginner
Beginner

Joined: Thu Oct 09, 2003 11:41 am
Posts: 39
Location: Paris, France
Hello,

I'm getting the NonUniqueObjectException exception

The mapping is as follows (simplified):
Code:
    <class name="User" table="user">
      <id name="id" column="user_id" type="long" unsaved-value="0">
         <generator class="hilo"/>
      </id>
      <property name="firstName" column="user_firstname" type="string" />
      <property name="lastName" column="user_lastname" type="string" />
<........>
        <many-to-one name="someObject" class="SomeObjectClass" column="some_object_column" cascade="save-update" />
      <joined-subclass name="JoinedObjectClass" table="joined_object">
         <key column="user_id"/>
<...>
</joined-subclass>
</class>


Now, when I'm trying to replace the someObject instance with a newly created instance of the same class, I'm getting the exception.

The code is as follows:

Code:
//activeUser is User object
public void setSomeObjectForUser(.....)
{
            SomeObjectClass someObjectInstance = new SomeObjectClass (title, activeUser, new LinkedList());
            session.save(someObjectInstance);
            activeUser.setSomeObject(someObjectInstance);
            session.saveOrUpdate(activeUser);

}
The exception is as follows:

Code:
Caused by: net.sf.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: 1, of class: JoinedObjectClass
   at net.sf.hibernate.impl.SessionImpl.checkUniqueness(SessionImpl.java:1666)
   at net.sf.hibernate.impl.SessionImpl.doUpdateMutable(SessionImpl.java:1435)
   at net.sf.hibernate.impl.SessionImpl.doUpdate(SessionImpl.java:1462)
   at net.sf.hibernate.impl.SessionImpl.saveOrUpdate(SessionImpl.java:1385)
   at mypackage.setSomeObjectForUser(myClass.java:999)
   ... 39 more


Thanks for any ideas why this would happen and how to fix it.


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

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.