-->
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: Delete order / Nullable checks on delete
PostPosted: Tue Dec 13, 2005 12:11 pm 
Beginner
Beginner

Joined: Tue Aug 03, 2004 1:13 pm
Posts: 23
Hibernate version:
2.1.8

I currently have the following scenario :

Class A manages a list of Class B (all-delete-orphan), and
Class M manages a list of Class N (all-delete-orphan).

B references N (not-null).

Now...if i remove an instance of B from A, it gets deleted because of the cascading. The same holds true for removing N from M.

the problem comes in when I have B' that references N' and I want to delete N.

I would assume it would be as easy as

Code:
A'.getBlist().remove( B' );
M'.getNList().remove( N' );
// commit the session.


Seesm simple enough. But what seems to be happening is that the cascade to N' happens first, putting N' into a deleted state, then the cascade to B' happens and fails.

This is because the doDelete routine first nulls out any transient(or deleted) references (N' is now deleted so B's ref is nulled). Then calls checkNullability, which fails stating that B's reference to N cannot be null..

Now...Why would we care about the referential integrity of a row about to be deleted?. It doesnt seem to make sense to checkNullability on an object that ii going to be deleted.

Note this is a Hibernate issue not a databse issue. I can manually delete the records from the db in one swoop just fine.

The following DOES work though :
Code:
A'.getBlist().remove( B' );
// flush
M'.getNList().remove( N' );
// commit the session


So..is there any way to control the order that the collections are cascaded to. Or to just fix the problem of verifying object state when deleting ?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 13, 2005 1:14 pm 
Beginner
Beginner

Joined: Tue Aug 03, 2004 1:13 pm
Posts: 23
This also works (as it forces the delete of B' )
Code:
A'.getBlist().remove( B' );
sess.delete( B' ); // force the delete rather than letting cascade pick it up.
M'.getNList().remove( N' );
// commit the session


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 14, 2005 1:07 pm 
Beginner
Beginner

Joined: Tue Aug 03, 2004 1:13 pm
Posts: 23
I tested this in H3 and have the same problem.


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.