OK, I have setup a scenaior previously where if I remove the relationship of a parent it will delete that child. That was a choir but with your good help I got it.
Now I have a more difficult situation. I have parent child relationship, however it was modeled as such. The database was modeled for many to many with join table. So I have a parent, child and parentchild table.
The join table parentchild has its own unique key as its primary key and then the two Foreign keys from parent and child. The save works fine but the delete I am having issues with. When I remove the relationship(i.e. remove from list) then I want it to delete parentchild row first then the child. The following is how it is mapped.
PARENT
<!-- bi-directional one-to-many association to ParentChild-->
<set name="ParentChild" lazy="false" inverse="true" cascade="all">
<key>
<column name="PARENT_ID" />
</key>
<one-to-many class="ParentChild" />
</set>
PARENT CHILD RELATIONSHIP
<class name="PARENT_CHILD" table="T_PARENT_CHILD" dynamic-update="true" lazy="false">
<id name="parentchildID" type="java.lang.Long" column="PARENT_CHILD_ID">
<generator class="sequence">
<param name="sequence">seq_001</param>
</generator>
</id>
<!-- Associations -->
<!-- bi-directional many-to-one association to Parent -->
<many-to-one name="parent" class="Parent" cascade="all" not-null="true" lazy="false">
<column name="PARENT_ID" />
</many-to-one>
<!-- bi-directional many-to-one association to Child-->
<many-to-one name="child" class="Child" not-null="true" cascade="all" lazy="false">
<column name="CHILD_ID" />
</many-to-one>
</class>
CHILD
<set name="ParentChilds" lazy="false" inverse="true" cascade="none" >
<key column="CHILD_ID" foreign-key="CHILD_ID"></key>
<one-to-many class="ParentChild" />
</set>
|