-->
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: How to delete large number of objects
PostPosted: Sun Mar 02, 2008 8:41 pm 
Newbie

Joined: Sun Mar 02, 2008 8:34 pm
Posts: 1
I have an operation that will generated a collection of
objects needs to be deleted from the database,
about 1 million of them.

The way I used now, is to delete the entry one by one in
one transaction.
iter = list.iterator();
tran.begin();
while(iter.hasNext())
sesssion.delete(iter.next());
tran.commit();

However, this has been really really slow.
And one thing I don't understand is why hibernate will first do
a select then do a delete.

How can I improve the performance in this situation?


Top
 Profile  
 
 Post subject: Re: How to delete large number of objects
PostPosted: Sun Mar 02, 2008 8:49 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
your best bet probably is to turn this into a hql, specially one that deletes a range of objects. This will eliminate the selects and improves performance of deletes. However, if you can't do this you might want to look at L2 cache to improve the performance with the selects, if the objects have been fetched on the same machine at some point. As for why selects happen, I would say its because those object are not managed and HB will have to go to database to make them managed.



Farzad-


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