-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: One-to-many relationship and composite-id
PostPosted: Fri Apr 29, 2005 2:54 pm 
Newbie

Joined: Fri Apr 29, 2005 2:35 pm
Posts: 7
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


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 29, 2005 2:56 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
look at package org.hibernate.test.orphan


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.