Hi,
As the subject says, I have a bi-directional many-to-many family/model relationship, mapped as cascade="all,delete-orphan" on the family side and inverse="true" on the model side. When I delete a family instance, Hibernate deletes all models attached to this family even models which are attached to others families.
Let's take an example :
family f1 with models m1,m2,m3 attached,
family f2 with models m1,m4 attached
The behaviour I expect is when I delete f1, I would like that Hibernate deletes f1 from the
family table, all "links" related to f1 in the join table and all models which are attached to f1 AND NOT attached to others families. So, with my example, I would like that Hibernate deletes only m2 and m3 when I delete f1 (m1 is attached to f2 also!).
my mappings :
Code:
<class name="Family" table="family">
<id name="uid">
<column name="fam_kuid" />
<generator class="sequence">
<param name="sequence">seq_family</param>
</generator>
</id>
<property name="name" column="fam_name" unique="true"/>
<set name="models" table="family_model" cascade="all,delete-orphan">
<key column="fam_kuid"/>
<many-to-many column="mod_kuid" class="Model"/>
</set>
</class>
<class name="Model" table="model">
<id name="uid">
<column name="mod_kuid" />
<generator class="sequence">
<param name="sequence">seq_model</param>
</generator>
</id>
<property name="name" column="mod_name" />
<set name="families" table="family_model" inverse="true" >
<key column="mod_kuid"/>
<many-to-many column="fam_kuid" class="Family"/>
</set>
</class>
Thanks for any help you may offer