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: Howto cascade delete: parent object doesn't reference child
PostPosted: Thu Dec 03, 2009 9:11 am 
Newbie

Joined: Thu Dec 03, 2009 8:58 am
Posts: 1
I have an interesting scenario that I am looking for a solution to.

I have a object "Parent" that maps to table "tblParent" and there is a child table "tblChild" with a foreign key constraint to tblParent. However the Parent object does not have a Children collection or any such. For the purpose of my code I don't need the children nor really care much about them. However, I do need to be able to delete parent records. This works fine as long at the parent has no children. When it has children the delete fails because NHibernate doesn't know about the child table and doesn't know to cascade the delete.

So my question is, what is the cleanest way to make NHibernate aware of the relationship and enable a cascading delete in this situation? I don't want to add a Children property to the Parent object since its not needed by the domain logic.

Regards,
Ken


Top
 Profile  
 
 Post subject: Re: Howto cascade delete: parent object doesn't reference child
PostPosted: Wed Dec 09, 2009 7:48 am 
Expert
Expert

Joined: Thu Dec 14, 2006 5:57 am
Posts: 1185
Location: Zurich, Switzerland
Do it in the database with "on delete cascade" on the foreign key.

_________________
--Wolfgang


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.