-->
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.  [ 4 posts ] 
Author Message
 Post subject: One to One Cascade Delete
PostPosted: Mon Apr 02, 2007 9:33 pm 
Newbie

Joined: Mon Apr 02, 2007 7:29 pm
Posts: 2
Location: Australia
I have a one to one relationship in my database.

UserTable
------------
UID
UserName
...

SecurityTable
SID
Name
...


In which UID is one to one mapping to SID
When I deleting row in UserTable I want it cascade on delete the SecurityTable row as well.


Can anyone give me some hints?

Here is bit in the mapping file that I am using. Appearanely its not working

<set
name="SecurityUser"
lazy="true"
inverse="true"
cascade="all-delete-orphan"
access="field.camelcase-underscore"
>
<key>
<column name="SID" />
</key>
<one-to-many
class="Domain.User, Security"
/>
</set>

_________________
Thanks,
Gary Lam.


Top
 Profile  
 
 Post subject: Re: One to One Cascade Delete
PostPosted: Mon Apr 02, 2007 9:52 pm 
Regular
Regular

Joined: Sun Jan 21, 2007 4:33 pm
Posts: 65
garylam wrote:
I have a one to one relationship in my database.

UserTable
------------
UID
UserName
...

SecurityTable
SID
Name
...


In which UID is one to one mapping to SID
When I deleting row in UserTable I want it cascade on delete the SecurityTable row as well.


Can anyone give me some hints?

Here is bit in the mapping file that I am using. Appearanely its not working

<set
name="SecurityUser"
lazy="true"
inverse="true"
cascade="all-delete-orphan"
access="field.camelcase-underscore"
>
<key>
<column name="SID" />
</key>
<one-to-many
class="Domain.User, Security"
/>
</set>


If its a one-to-one relationship, then you shouldn't have a 'set' or one-to-many in the mapping file. The PK of the Parent Table should be related to the Parent Key of the Child table in a One-To-One relationship.

One-To-One Explained here: http://www.hibernate.org/hib_docs/nhibe ... n-onetoone

AFAIK, you'll need to fix your mappings, then follow the directions here to Cascade delete:

http://www.hibernate.org/hib_docs/nhibe ... a-deleting


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 03, 2007 12:09 am 
Newbie

Joined: Mon Apr 02, 2007 7:29 pm
Posts: 2
Location: Australia
I changed the set to the following one-to-one relationship. I guess it will automatic map the primary key.

However when I follow your link to delete and flush the User object the cascade on delete still doesn't happen.

Here is the new one to one relationship.

<one-to-one
name="SecurityUser"
class="Domain.User, Security"
cascade="all-delete-orphan"
/>

_________________
Thanks,
Gary Lam.


Top
 Profile  
 
 Post subject: Re: One to One Cascade Delete
PostPosted: Fri Aug 20, 2010 8:00 am 
Newbie

Joined: Fri Aug 20, 2010 7:57 am
Posts: 7
i changed my xml file tag
<one-to-one name="address" class="com.hibernate.Address" cascade="save-update"/>
to
<one-to-one name="address" class="com.hibernate.Address" cascade="all"/>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.