-->
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: Problem with deleting bulk of records in MS Sql server.
PostPosted: Thu Sep 18, 2008 9:22 am 
Newbie

Joined: Mon Sep 08, 2008 9:31 am
Posts: 2
Location: Hyd
Hi all,


From application, I have a collection of objects where i am trying to delete object by object by checking some condition. Suppose there are more than 100 objects in loop, every time it has to go to DB server and delete each object, so a lot of trips. The problem is, application is getting stuck after deleting all, probably because of attempting all deletes in a single transaction, so the app can’t commit the transactions until it has too much to cope with. so finally it is rolling back.

DB server is : MS SQL server.

Please suggest.
thanking you in advance,

illi.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 18, 2008 4:13 pm 
Expert
Expert

Joined: Mon Nov 26, 2007 2:29 pm
Posts: 443
Basically you have 2 options, none of them too attractive.
The first is to manually write a native SQL query.
The second (preferable?) is to set your database to CASCADE DELETE, and configure your Hibernate mappings accordingly.

I wrote an article here discussing those 2 approaches in detail, with code examples.

_________________
Gonzalo Díaz


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 19, 2008 1:36 am 
Newbie

Joined: Mon Sep 08, 2008 9:31 am
Posts: 2
Location: Hyd
Hi,

Thanks for your repl
I will explain more clearly now,

Objects obj[]=new Objects[100... more];
for(n=0;n<obj.length;n++){
session.delete(obj[n]); // object has children.
}

My code is like above. here object has too many children. of course session.delete will cascade all its children. Actually i tried to use a native query to delete all of them, but it wont do cascading part it seems. it was simply throwing error as it has children undeleted. Can' I delete complete array in a single call.

I mean, anything that works like session.delete(collection/array);

or is flush usefule here?

Thanks again,
illi


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.