[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?
|