the mapping is like this:
[code]<class name="FirstObject" table="FirstObjects">
<id name="firstObjectId" type="long">
<generator class="native"/>
</id>
<property name="propertyOfFirstObject"/>
<joined-subclass name="SecondObject" table="SecondObjects">
<key column="firstObjectId"/>
<property name="propertyOfSecondObject"/>
<joined-subclass name="ThirdObject" table="ThirdObjects">
<key column="secondObjectId"/>
<property name="propertyOfThirdObject"/>
</joined-subclass>
</joined-subclass>
</class> [/code]
The SecondObject already exists in database. Now I want to insert one ThirdObject.
if I do:
SecondObject s = session.load(SecondObject.class, firstObjectId);
ThirdObject t = new ThirdObject ();
t.setId(s.getId());
t.setPropertyOfThirdObject("test");
session.save(t);
I got this error:
org.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session:
if i do session.merge(t), i got this error:
org.hibernate.WrongClassException: Object with id: null was not of the specified subclass:
Any idea?
Thanks!
|