Hibernate Version: 2
People,
I have some use cases that we made a MasterDetail cadastre (like employees and their dependents).
So, when I delete an employee, hibernate just sets as NULL the foreign key for employee in dependents table, but what i realy wants is that hibernate also delete all dependents for that employee, how can I do that? Does anybody know?
Those are my hbm's
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 1.1//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class
name="br.com.softsite.sample.model.Dependent"
table="DEPENDENT"
>
<composite-id class="br.com.softsite.sample.model.DependentId" name="id">
<key-property name="id" column="ID" type="integer"></key-property>
<key-many-to-one name="employee" column="EMPLOYEE_FK" class="br.com.softsite.sample.model.Employee"></key-many-to-one>
</composite-id>
<property
name="depName"
type="java.lang.String"
>
<column
name="DEP_NAME"
unique="false"
sql-type="VARCHAR(255)"
/>
</property>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-ClasseDetalhe.xml
containing the additional properties and place it in your merge dir.
-->
</class>
</hibernate-mapping>
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 1.1//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class
name="br.com.softsite.sample.model.Employee"
table="EMPLOYEE"
>
<id
name="id"
column="ID"
type="java.lang.Integer"
>
<generator class="hilo">
</generator>
</id>
<property
name="empName"
type="java.lang.String"
>
<column
name="EMP_NAME"
unique="false"
sql-type="VARCHAR(255)"
/>
</property>
<set
name="theDependent"
lazy="true"
inverse="false"
cascade="all"
sort="unsorted"
>
<key
column="EMPLOYEE_FK"
/>
<one-to-many
class="br.com.softsite.sample.model.Dependent"
/>
</set>
</class>
</hibernate-mapping>
thank's
Roberto C. Lima Jr
|