I have a bidirectional relationship like this.
Code:
<class name="A" table="a">
<id name="ID" type="int" unsaved-value="null">
<column name="ID" sql-type="int" not-null="true"/>
<generator class="native"/>
</id>
...
<bag name="bitems" table="b" cascade="all">
<key column="bref"/>
<one-to-many class="B"/>
</bag>
</class>
and
Code:
<class name="B" table="b">
<id name="ID" type="int" unsaved-value="null">
<column name="ID" sql-type="int" not-null="true"/>
<generator class="native"/>
</id>
<many-to-one name="aitem" class="A" column="bref"/>
When I try to insert something I get the following errors:
Code:
net.sf.hibernate.HibernateException: SQL insert, update or delete failed (row no
t found)
at net.sf.hibernate.impl.NonBatchingBatcher.addToBatch(NonBatchingBatche
r.java:25)
at net.sf.hibernate.collection.AbstractCollectionPersister.recreate(Abst
ractCollectionPersister.java:526)
at net.sf.hibernate.impl.ScheduledCollectionRecreate.execute(ScheduledCo
llectionRecreate.java:23)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2449)
at net.sf.hibernate.impl.SessionImpl.executeAll(SessionImpl.java:2435)
at net.sf.hibernate.impl.SessionImpl.execute(SessionImpl.java:2396)
at net.sf.hibernate.impl.SessionImpl.flush(SessionImpl.java:2261)
at net.sf.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.j
ava:61)
...
I think it has something to do with the fact that the relationship is bidirectional but I'm not sure. Can anyone help? Setting inverse="true" in the bag tag doesn't help