Hello there, I'm using hibernate 3.1.2, and I have a one-to-many association using a set. My cascade is set to save-update. When I add a new element to my collection and update it, it's generating a insert for the new element (expected) and updating every element of the collection, plus updating the other entities:
It inserts a new vote, updates all votes in the collections and updates voter and building. I was expecting only insert to happen
Here's my mapping:
Code:
<hibernate-mapping
>
<class
name="Voter"
table="VOTER"
>
<id
name="id"
column="ID"
type="java.lang.Long"
>
<generator class="sequence">
<param name="sequence">SEQ_VOT</param>
</generator>
</id>
<set
name="votes"
lazy="false"
inverse="true"
cascade="save-update"
sort="unsorted"
>
<key
column="ID_VOTER"
>
</key>
<one-to-many
class="Vote"
/>
</set>
</hibernate-mapping>
<hibernate-mapping
>
<class
name="Vote"
table="VOTE"
>
<id
name="id"
column="ID"
type="long"
>
<generator class="sequence">
<param name="sequence">SEQ_VOTE</param>
</generator>
</id>
<many-to-one
name="building"
class="Building"
cascade="none"
outer-join="auto"
update="true"
insert="true"
column="ID_BUILD"
/>
<many-to-one
name="voter"
class="Voter"
cascade="none"
outer-join="auto"
update="true"
insert="true"
column="ID_VOTER"
/>
</class>
</hibernate-mapping>
It's a simple voting mechanism, where for each vote we track the voter and the building he voted for.
Any ideas?
Regards