-->
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.  [ 4 posts ] 
Author Message
 Post subject: best way to update multiple rows in db
PostPosted: Mon May 30, 2005 1:51 pm 
Beginner
Beginner

Joined: Tue Feb 17, 2004 11:20 am
Posts: 28
Hi,

I have read few post in the forum related to this issue, but I still have some questions.

I know very well that Hibernate is orm so it's not designed to run updates on multiple rows. but there is a situation when it can be useful.

sometimes I need to change a flag on several rows, not 10,20 but 500 or 1000 rows. And here sql is the winner to do the tast as I can write something like

update data set flag = 'x' where flag = 'z'

My guess is to get the statement from the session and issue an sql on the db. but my concern is what happends with the session and secondary cache. how ehcache will realize that I updated 1000 records in the background

is there a way to do this the best possible way with hibernate ??

Thanks for any suggestions!!!

Istvano

Hibernate version:
2.8


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 30, 2005 7:29 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
See the blog for a commentary on Batching
http://blog.hibernate.org/cgi-bin/blosxom.cgi/index.html?find=batch&plugin=find&path=

Also H3 supports batch updates (and deletes) natively in HQL so an updates as you have shown can be performed directly.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 30, 2005 11:54 pm 
Expert
Expert

Joined: Thu May 26, 2005 9:19 am
Posts: 262
Location: Oak Creek, WI
Hi

Consider If i have to insert 1000 records then 1000 insert queries would be executed.

Can i do it in a Single Query?

And my Other Question is How do it handle the Connection here. If i go on inserting 1000 records will my connection pool get exhausted.

Consider i open the connection in the Constructor and close the connection in the finally block in all the methods. If that is the case i wont be able to close the connection and my connection pool will get exhausted.

_________________
RamnathN
Senior Software Engineer
http://www.linkedin.com/in/ramnathn
Don't forget to rate.


Top
 Profile  
 
 Post subject: thx
PostPosted: Tue May 31, 2005 6:17 am 
Beginner
Beginner

Joined: Tue Feb 17, 2004 11:20 am
Posts: 28
Thanks for the reply, it was quite helpfull. for the moment I have to stay with hb2.8 so I will do the scroll stuff.

Thanks

Istvano


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