We are looking at Hibernate to use it in of our new projects. In the test following scenario, An animal can go to multiple shows. I am createing an Animal object, a set of 2 shows and assigning the set to animal object. The logs show that a row is inserted in the Animal table and then 2 rows in the Show table (for 2 shows where this ANimal is supposed to go). Then an update is called to update the Show rows with a value which it is already having. I do not understand why is the update being called? I think I am missing something here. Can someone please help? Thanks in Advance
Code:
<hibernate-mapping>
<class name="events.Animal" table="Animal">
<id name="id">
<generator class="native"></generator>
</id>
<property name="name" column="name"></property>
<set name="shows" inverse="false" cascade="all">
<key column="aid" not-null="true"/>
<one-to-many class="events.Show"/>
</set>
</class>
<class name="events.Show" table="Show1">
<id name="id">
<generator class="native"/>
</id>
<property name="name" column="name"/>
</class>
</hibernate-mapping>
insert into Animal (name) values (?)
Hibernate: insert into Show1 (name, aid) values (?, ?)
Hibernate: insert into Show1 (name, aid) values (?, ?)
Hibernate: update Show1 set aid=? where id=?
Hibernate: update Show1 set aid=? where id=?
MySQL logs
081017 22:20:23 4 Query insert into Animal (name) values ('horse10')
4 Query insert into Show1 (name, aid) values ('london10', 30)
4 Query insert into Show1 (name, aid) values ('London11', 30)
4 Query update Show1 set aid=30 where id=25 // is aid not already saved as 30 in the previous line?
4 Query update Show1 set aid=30 where id=26 // line2
4 Query commit