-->
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.  [ 3 posts ] 
Author Message
 Post subject: Deleting referenced objects
PostPosted: Thu Mar 10, 2011 9:14 am 
Beginner
Beginner

Joined: Mon Nov 15, 2010 10:39 am
Posts: 27
Hi,

I am working on a Hibernate databased created from the basis of a uml class diagram, where uml classes are tables with their attributes as columns, and the uml associations become tables with foreign keys referencing 2 (class) tables. My problem occurs when i try to delete an entry in one of the (class) tables, which is referenced by another (association) table. I get a constraintviolationexception on the foreign key of the referencing table (which is no shock really).

My question is this: What are my options with regards to handling this? I have found the cascading delete function, which is alright as a worst case, but what i am really looking for is something like setting the columns in the referencing table entries to null if the referenced entry is deleted. This is as far as i can see possible in SQL, by manipulating the foreign key constraint to have ON DELETE SET NULL. I also see that this is not possible with Hibernate (pending ticket about this).

Is there currently a fairly simple way of doing this with Hibernate (could the foreign keys perhaps be manipulated "directly" through HQL queries?)? Are there any other options to cascading the delete?

Regards,

Tobb


Top
 Profile  
 
 Post subject: Re: Deleting referenced objects
PostPosted: Thu Mar 10, 2011 10:48 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
Just set the constraint to "on delete set null" and be happy. The exception is thrown by you database, not by hibernate.

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
 Post subject: Re: Deleting referenced objects
PostPosted: Sat Mar 12, 2011 5:22 am 
Beginner
Beginner

Joined: Mon Nov 15, 2010 10:39 am
Posts: 27
Well how do i set this through hibernate?


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