I'm using hibernate 2.1.2 , and discovered that this mapping causes
problem while flushing.
Course.hbm.xml:
Code:
<bag name="groups" lazy="true" cascade="delete">
<key/>
<one-to-many class="com.infodesire.educator.data.Group"/>
</bag>
Group.hbm.xml:
Code:
<many-to-one name="course" not-null="true" cascade="none"/>
I create group following way:
Code:
Group group = new Group();
course.getGroups().add(group);
group.setCourse(course);
Session session = obtainSession();
session.save(group);
returnSession(session);
Then while flushing session, it tries to update collection
and botches primary key instead updating foreign key:
Code:
7745 [main] DEBUG net.sf.hibernate.SQL - update course_group set id=? where id=?
Hibernate: update course_group set id=? where id=?
7746 [main] DEBUG net.sf.hibernate.impl.BatcherImpl - preparing statement
7748 [main] DEBUG net.sf.hibernate.type.IntegerType - binding '1' to parameter: 1
7749 [main] DEBUG net.sf.hibernate.type.IntegerType - binding '1' to parameter: 2
7749 [main] DEBUG net.sf.hibernate.impl.BatcherImpl - Adding to batch
7760 [main] DEBUG net.sf.hibernate.type.IntegerType - binding '1' to parameter: 1
7761 [main] DEBUG net.sf.hibernate.type.IntegerType - binding '2' to parameter: 2
7761 [main] DEBUG net.sf.hibernate.impl.BatcherImpl - Adding to batch
When I specify column names explicitely on both sides, everything is fine.
And dtd says that column names for foreighn key are implied...
Is it minee fault or yours?