I am using ILifecycle under NHibernate 1.2.0 CR1 and hitting a limitation of the LifecycleVeto for OnDelete. I have an entity with a child collection that is configured for cascade="all-delete-orphan". If I delete the top most object, the whole object graph is deleted from the database which is great. If I have logic in ILifecycle.OnDelete for the top object and return a LifecycleVeto.Veto, then the whole deletion is canceled as I would hope. However, if it is one of the child objects that returns the Veto in its own ILifecycle.OnDelete, NHibernate still tries to persist the deletion of the parent (and other children). In my case, an exception subsequently results from the violation of a database foreign key constraint.
I would guess this is "functions as designed", but I figured I would see if anyone has any creative solutions to this other than just checking all child objects from the parent's OnDelete?
It seems like it would be a nice enhancement to ripple a child's Veto up the dependent collection chain. Although, I would imagine there would need to be some clear restrictions (e.g. a one to many relationship with cascade...) or have this be configurable in some way.
Another workaround would be to throw a CallbackException in the child's OnDelete, but that doesn't feel right for a "normal" execution flow. In my case, I am trying to not delete this object graph if some outside entity has a many-to-many association into one of the child objects.
|