Question

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 associated 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" />

Was it helpful?

Solution

In your course object you need to set the cascade option on what I presume will be a bag or similar with a one-to-many inside.

<bag name="Tutorials" cascade="all-delete-orphan">
   <key column="someId" />
   <one-to-many class="Tutorial" not-found="ignore" />

Hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top