HB 2.1.2
Hi,
The following setup was working fine with, IIRC, HB 2.0. Now, I'm getting the
net.sf.hibernate.NonUniqueObjectException: a different object with the same identifier value was already associated with the session: 0, of class: test.Child
Mappings:
Code:
<hibernate-mapping schema="test">
<class name="test.Parent" table="Parent" >
<id name="id" type="int" unsaved-value="0">
<generator class="sequence">
...
</id>
...
<bag name="children" inverse="true" lazy="true" cascade="all">
<key column="parentId"/>
<one-to-many class="test.Child"/>
</bag>
</class>
</hibernate-mapping>
<hibernate-mapping schema="test">
<class name="test.Child" table="Child" >
<id name="id" type="int" unsaved-value="0">
<generator class="sequence">
</generator>
</id>
...
<many-to-one name="Parent" class="test.Parent" column="parentId"
not-null="true" unique="false"/>
</class>
</hibernate-mapping>
Code:
Code:
...
for (int i = 0; i < blockSize; i++) {
Parent parent = new Parent();
Child Child = new Child();
Child.setParent(parent);
List children = new ArrayList();
children.add(Child);
parent.setChildren(children);
parents.add(Parent);
}
Transaction tx = session.beginTransaction();
for (int i = 0; i < blockSize; i++) {
// with i = 1 the exception is thrown on save()
session.save(securities.get(i));
}
session.flush();
tx.commit();
...
It appears that HB goes to the db to get ids for the first 2 Parents but never tries to get the id for the Child.
Any ideas? Thanks