-->
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.  [ 1 post ] 
Author Message
 Post subject: Deleting children - best practice?
PostPosted: Thu Jul 14, 2005 8:36 am 
Regular
Regular

Joined: Sun Nov 07, 2004 3:39 pm
Posts: 77
[I'd worry about this title if it were on any other forum...]

Let's say I have a Parent object, with a Collection of Children. The cascade is marked as 'all-delete-orphan'. When the parent object is saved, all changes to the children collection are made, too. This is done in a single 'storeParent' service method which is wrapped in a transaction, courtesy of Spring.

Now, I want to prevent the transaction from completing if one of the children to be deleted has a certain condition attached (it may be being used somewhere, it doesn't really matter what). But what can I do in this 'storeParent' method to effect that? The collection which is being stored as part of the parent record no longer contains the child, because it has been removed from the collection in, say, my Struts action as the first stage of deleting it.

There are two ways I can think to do this: firstly, load the 'old' collection and compare, which is certainly messy; or secondly, don't actually remove the objects from the collection but set some flag indicating that they need to be removed and handle that in the service method. It strikes me there has to be a better way than this, though. What do others do?


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

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.