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.  [ 2 posts ] 
Author Message
 Post subject: Removing Parents without Children
PostPosted: Wed May 21, 2008 7:27 pm 
Newbie

Joined: Wed May 21, 2008 7:24 pm
Posts: 2
Is there a way to tell nhibernate to delete the parent when the last child is removed (child collection is empty) without having to explicitly delete the parent?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 28, 2008 4:34 pm 
Expert
Expert

Joined: Fri Oct 28, 2005 5:38 pm
Posts: 390
Location: Cedarburg, WI
AFAIK there is no mapping capability for this. We've handled it by having our implementation of IInterceptor call a protected OnDelete() method on the entity via reflection (sort of like our own ILifecycle implementation). In the child's OnDelete(), it checks if there are no other siblings left in the parent's collection, and if none, it deletes the parent. This way at least, application-level code isn't responsible for it, and guarantees that it always gets cleaned up.

I know this violates the rule that stuff in IInterceptor shouldn't make additional changes to the session, but it works fine for us ...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.