-->
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: Deleting objects from collection while detached
PostPosted: Wed Nov 24, 2004 4:01 pm 
Newbie

Joined: Wed Feb 04, 2004 2:33 pm
Posts: 10
I searched around a bit and could not find this exact situation in the forums. One thread was close http://forum.hibernate.org/viewtopic.php?t=928459 but there was some copying of collection elements going on which confused the issue. My question is much more straightforward.

Given this scenario:

- load parent and initialize a one-to-many collection of children in session 1
- close session 1
- delete some children from the parents collection
- open session 2
- re-attatch parent using session2.update
- flush session 2

Note that the deletes happened while the parent was detached...


What should happen if one-to-many is cascade="all"? Will it "unlink" the deleted children, but not delete them?


What should happen if the one-to-many is cascade="all-delete-orphan"? Does this actually remove the children from the database


Hibernate version:
2.1.6


Name and version of the database you are using:
SQL Server 2000


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 24, 2004 4:10 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
all delete orphan does the job but be sure the children aren't associated with another parent....

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 01, 2004 10:56 am 
Newbie

Joined: Wed Feb 04, 2004 2:33 pm
Posts: 10
anthony wrote:
all delete orphan does the job but be sure the children aren't associated with another parent....


Thanks for your reply. all-delete-orphan is deleting the children that were removed from the collection while the parent was detached, but I noticed that Hibernate is generating an Update statement for every collection element, even though they have not changed. Is this where versioning comes into play?

Thanks again,
Mike


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 02, 2004 2:08 am 
Expert
Expert

Joined: Tue Oct 05, 2004 9:45 am
Posts: 263
i think the update statements are generated because hibernate is not able to determine if the values have changed (the parent and children are detached - no previousState available) ...

i don't know if that works, but you could give "select-before-update" a change ...

gtx
curio


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.