tags:

views:

78

answers:

2

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>

A: 

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.

Brian Yarger
thanks for reply.But i tried setting this properties in course.hbm and tried to delete , but tutorials and applications are not geting deleted.not that i have invers maping in application.i need to set this properties in coure.hbm or tutotials.hbm and application.hbm?
hey i have posted my application.hbm here just have a look.
A: 

While it may be possible to do that on hibernate, the Correct Way (which ensures the integrity of the database at all times) is to use CASCADE ON DELETE constraints on the database level. Check your database documentation for details

kazanaki
i want todo it with hibernate and not at DB level