-->
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: Question about object deletion ...
PostPosted: Tue Sep 12, 2006 11:19 am 
Newbie

Joined: Mon Sep 11, 2006 9:40 am
Posts: 5
Hibernate version:
3.1

Name and version of the database you are using:
Oracle 10g

Specifically, making the distinction between "ownership" and "reference". In our model, a User object may "own" many contacts but a contact also has a "reference" to another User which is the target of the contact. When the owning User gets deleted, all of its owned contacts should get deleted. However when a User gets deleted, any contact that reference that User as as target should not get deleted. It's reference should just be set to NULL.

In this specific case(User-Contact), it is possible to just query for all contacts whose target is the to-be-deleted user and then do user.setTarget(null). This works fine, but my question is more generic. Is there any way to make hibernate update all those foreign keys to the User to NULL when the User gets deleted without doing this explicit object.setTarget(null). Going forward, we may have these non-ownership references peppered throughout the model and writing explicit code to clean them up will get very tedious.

The only solutions that I have seen to this so far is to use "ON DELETE SET NULL" on the foreign key, but this seems like it would have at least 2 problems:
1. Your in-memory transient objects now have bad data after the commit because hibernate doesn't know that the database just nulled out a lot of references.

2. Potential issues with the 2nd-level cache for the same reason. This would be more of a problem with us.
l
Any and all comments would be greatly appreciated.

Thanks.


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.