-->
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: all-delete-orphan deleting non-orphans
PostPosted: Mon Mar 13, 2006 7:11 pm 
Newbie

Joined: Mon Mar 13, 2006 7:07 pm
Posts: 8
I have 3 Objects.

A references C
and
B references C

If I set the A->C cascade to "all-delete-orphan" and remove an instance of C from an instance of A and save..

Hibernate deletes the instance of C even if there is an instance of B that references it.

Is this a bug?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 13, 2006 7:32 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
No, not really. Hibernate doesn't do a "select count(*) from * where *.Cid = :CidBeingDeleted", because there is no (easy) way to find all references to C from any table. If only there was! The delete-orphan bit works on one-to-many and many-to-many relationships, and only on the relationship that the delete-orphan is defined on.

If you want to conditionally delete C in this case, your best bet is to add an sql-delete element in A's mapping, and do the delete in a stored procedure. That proc can check other relationships, and return 0 instead of deleting C, if C can't be deleted yet.


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:
cron
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.