-->
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.  [ 7 posts ] 
Author Message
 Post subject: Force single delete?
PostPosted: Fri Sep 08, 2006 7:39 am 
Beginner
Beginner

Joined: Thu Jul 06, 2006 4:44 am
Posts: 31
Hello.

I have a parent object with the list of the depending children objects (one-to-many)...After setting the list to null and updating the parent object nhibernate executes a delete statement for each single child object in the list. THis takes to long and it is a performance loss.

Is there any way to delete n children in a single statement????
(like: delete child where parent = 1)???

thanx for any reply.

markov


Top
 Profile  
 
 Post subject: Re: Force single delete?
PostPosted: Fri Sep 08, 2006 8:41 am 
Beginner
Beginner

Joined: Wed Aug 03, 2005 8:06 am
Posts: 40
Location: Netherlands
markov wrote:
After setting the list to null.


Does it help if you do list.Clear();? See http://www.hibernate.org/hib_docs/nhibernate/html/performance.html#performance-collections-oneshotdelete (although this reference suggests that your approach should work too).


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 08, 2006 9:05 am 
Beginner
Beginner

Joined: Thu Jul 06, 2006 4:44 am
Posts: 31
list.Clear() deletes all children but still one by one....

any idea how to write it in standard SQL?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 08, 2006 9:21 am 
Regular
Regular

Joined: Mon Jul 18, 2005 4:10 am
Posts: 92
Location: Poland
maybe
session.Delete("from object o where o.Parent.id=...")

btw. I think GeAr is right, just follow the link he provided. Or we misunderstand your problem.

_________________
michal


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 08, 2006 9:28 am 
Beginner
Beginner

Joined: Thu Jul 06, 2006 4:44 am
Posts: 31
michal wrote:
maybe
session.Delete("from object o where o.Parent.id=...")

btw. I think GeAr is right, just follow the link he provided. Or we misunderstand your problem.


your example still executes multiple delete statements.
like:
delete child where id = ....
delete child where id = ....
delete child where id = ....
delete child where id = ....

deleting 1000 childs takes about 10 seconds and one sigle query takes 0 seconds for the same result!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 08, 2006 9:42 am 
Regular
Regular

Joined: Mon Jul 18, 2005 4:10 am
Posts: 92
Location: Poland
Hm that's strange. I didn't tested it but I'm sure I used "one shoot delete" without problems. Looks like some driver or dialect issue, btw. what db driver/dialect you are using?

As a workaround I can propose sth like this:
IDBConnection conn=session.Connection()
IDBCommand cmd=conn.CreateCommand()
cmd.CommandText="delete from table where idparent=...."
cmd.ExecuteNonQuery()

_________________
michal


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 08, 2006 10:23 am 
Beginner
Beginner

Joined: Thu Jul 06, 2006 4:44 am
Posts: 31
("hibernate.connection.provider" ,"NHibernate.Connection.DriverConnectionProvider");
("hibernate.dialect" ,"NHibernate.Dialect.MsSql2000Dialect");
("hibernate.connection.driver_class" ,"NHibernate.Driver.SqlClientDriver");


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