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.