i have a course object. The course object has a set of tutorials and a set of applications.
When i delete a course objects i want the assocated set of tutorials and applications to get deleted.
My course.hbm is as follows
and my application.hbm contains
<property name="appdatetime" type="timestamp">
<column name="appdatetime" length="19" />
</property>
<property name="appstatus" type="java.lang.Integer">
<column name="appstatus" />
</property>
<property name="apptype" type="java.lang.Integer">
<column name="apptype" />
</property>
<many-to-one name="course" column="cid"/>
<many-to-one name="employee" column="empid" />
</class>
Set the cascade=”delete-orphan,all” and the delete operation will cascade down to the tutorials and applications and delete them as well if they’re orphaned (not connected to any other course).
We use hibernate annotations, so I’m not really sure the exact xml to add, but from the docs, it looks like cascade=”all-delete-orphan” should be on each of those collection definitions.