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 entitites with foreign keys pointing to them
PostPosted: Fri May 08, 2009 10:46 am 
Newbie

Joined: Wed Oct 08, 2008 10:11 am
Posts: 3
I've been using NHibernate for quite some time now, but as of late have been struggling with one little aspect regarding deletes. Lets take the contact - address example, it's not ideal, but it'll do. An address has a foreign key to contact and a contact has no notion of addresses.

When we would like to delete a contact, it's crucial that no contact can be deleted when they have an address assigned. But how would one go about checking this? I could before deleting the contact check using the address repository if there's any address assigned to the contact, but this doesn't really feel right, we'd like to add extra classes with foreign keys to contact and we would have to update this logic every time.

The crucial part here is that the relation is known in one direction only and cascading deletes isn't an option. I don't want to add addresses to a contact either, which would make the checking very straightforward though.

Could there be a kind of generic method to check for foreign key conflicts when deleting an entity? Wrapping the delete in a try-catch block would do the trick, but that's just wrong.

Thanks in advance.


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.