如何在Hibernate中级联删除?

时间:2022-11-23 03:40:12

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

我有一个课程对象。课程对象有一组教程和一组应用程序。当我删除课程对象时,我希望删除相关的教程和应用程序集。我的course.hbm如下,我的application.hbm包含

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

1 个解决方案

#1


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.

希望这可以帮助。

#1


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.

希望这可以帮助。