-->
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.  [ 6 posts ] 
Author Message
 Post subject: Cascading Deletes Causing Too Many Sql Deletes
PostPosted: Mon Apr 16, 2007 5:16 pm 
Newbie

Joined: Mon Apr 16, 2007 5:11 pm
Posts: 5
Hibernate version: 1.2

Name and version of the database you are using: MSSQL 2005

Basically after loading a bag of items, I am calling a IList.Clear() and watching the sql being generated. I see it doing single line deletes for each entry in the bag. I thought when doing a .Clear() that nHibernate was supposed to do a single delete. Does this not work with a Bag item and I have to use some other collection item?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 17, 2007 2:29 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
NHibernate will delete all the items from a collection if you set the collection reference to null, not if you use Clear.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 17, 2007 10:41 am 
Newbie

Joined: Mon Apr 16, 2007 5:11 pm
Posts: 5
Okay thanks, however now if I have my cascade="all" it doesn't seem to flush the deletes when saving the parent, which I kinda understand due to the idea that it is no longer referenced by the parent. However then I would think I should use the cascade="all-delete-orphan" which errors out saying you cannot dereference a collection with it. Do I need to retain some other reference to the child collection and flush that out seperatly?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 19, 2007 9:30 am 
Beginner
Beginner

Joined: Thu Apr 19, 2007 5:37 am
Posts: 28
the documentation states that you should change the reference of the collection, you have to keep the same, delete all its items, and add the new items.

hope this helps


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 19, 2007 10:31 am 
Newbie

Joined: Mon Apr 16, 2007 5:11 pm
Posts: 5
When using "all-delete-orphan" an nhibernate exception will be thrown when dereferencing the collection. If I use "all" instead no deletes will be made, only the dereferencing of the children in one update statement ( Update children set parentid = null where parentid = xx).

If I use cascade="all-delete-orphan" and just clear the list of my children, it will cause one update to dereference all the children from the parent and then single deletes for each child, and this is what I don't want.

If any one can give me an example of code with a simple parent/child relationship that will execute a single delete of all children when cleared from the parent that would be great. Also is there a way to force this delete or dereference with out loading the data for the children. If all I am doing is the delete/remove, I don't believe that it should load there data first. If there is no way of doing this I can write my own HQL/SQL statements to take care of it I was just hoping there is an easier way with nHibernate.


Top
 Profile  
 
 Post subject: Is the documentation wrong?
PostPosted: Thu Apr 19, 2007 12:50 pm 
Newbie

Joined: Thu Jan 26, 2006 4:22 pm
Posts: 6
Accoring to this http://www.hibernate.org/hib_docs/nhibe ... shotdelete
piece of the documentation this should all work. I too would be curious to see an example where that is indeed the case.

/Chris


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