-->
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: OneToMany ON DELETE SET NULL
PostPosted: Sun Nov 21, 2010 9:45 am 
Beginner
Beginner

Joined: Sun Apr 25, 2010 7:14 am
Posts: 30
Hi,

i have a quite huge project with a lot of OneToMany relations. The problem is that hibernate doesn't set the foreign key to NULL when
i delete a parent entity. So a value remains in the database that doesn't exist anymore (producing errors in hibernate core).

Is there any way to tell hibernate to set every foreign key to NULL or is the only way to do this a ON DELETE SET NULL constraint in
the database? If the only way is the constraint how can i avoid hibernate seeing the wrong state (cache)?

Thanks for your help

Yours
Thomas


Top
 Profile  
 
 Post subject: Re: OneToMany ON DELETE SET NULL
PostPosted: Tue May 24, 2011 3:28 pm 
Beginner
Beginner

Joined: Sat Sep 17, 2005 6:50 am
Posts: 23
I think that is exactly what controlled by inverse property:
  • if inverse=false, then when collection entry is removed, the parent key is set to null (update child set parent_id = null where parent_id = ?)
  • if inverse=true, then when collection entry is removed, it is deleted by key (delete from child where id = ?)


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.