-->
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: Update behaviour
PostPosted: Mon May 14, 2007 2:33 pm 
Newbie

Joined: Sun Mar 18, 2007 12:15 pm
Posts: 19
Hi

I have a class called X.

X contains a property Y defined as

IList<z> Y = new List<z>();

Y is represented in the .hbm.xml as:

<bag name="Y" inverse="false" table="Y_table" cascade="save-update" lazy="false" >
<key column="YId"></key>
..
..
/>

If I remove one of the list items in Y, and perform a Update on X,,, the corresponding row in Y_table is not removed, instead the YId is set to null.

Is this a correct behaviour, and is there any way to change this?

//lasse


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 15, 2007 4:01 am 
Expert
Expert

Joined: Tue Aug 23, 2005 5:52 am
Posts: 335
I believe that this is the expected behavior.

It looks like you are modeling a parent/child relationship where X is the parent and Y are the children. If you want the child item to be deleted when it is removed from the collection I think you can use cascade="all-delete-orphan" - this should also delete the child if the parent is deleted.

Symon.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 15, 2007 4:01 pm 
Newbie

Joined: Sun Mar 18, 2007 12:15 pm
Posts: 19
merge_s.rottem wrote:
I believe that this is the expected behavior.

It looks like you are modeling a parent/child relationship where X is the parent and Y are the children. If you want the child item to be deleted when it is removed from the collection I think you can use cascade="all-delete-orphan" - this should also delete the child if the parent is deleted.

Symon.


This seems correct...
I've read that in some applications, the "Delete" command only sets a bit "isDeleted" in the table, to be able to trace changes. Is there a "best practice" to achive this function?.


//lasse


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 16, 2007 4:02 am 
Expert
Expert

Joined: Tue Aug 23, 2005 5:52 am
Posts: 335
I don't know if there's a "best practice" but there have been several discussions on this forum and the Hibernate one too. Look for "logical delete" on the forums.

Cheers,

Symon.


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.