简体   繁体   中英

How to cascade a deletion in Hibernate?

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM