-->
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.  [ 5 posts ] 
Author Message
 Post subject: How to do update on rowsets
PostPosted: Tue Feb 10, 2004 2:35 pm 
Beginner
Beginner

Joined: Tue Feb 10, 2004 2:30 pm
Posts: 25
What is the correct way to use Hibernate to do a rowset update to the database without reading the collection first?

For example, in SQL:
UPDATE EMPLOYEES
SET salary = salary + 10000
WHERE salary < 50000

Is there a direct way to do this in Hiberate, or do I need to drop to a JDBC PreparedStatement to set the WHERE clause variable (in this case, the 50000 is variable)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 10, 2004 2:37 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
You can't execute a direct UPDATE with Hibernate, use Session.connection() to get a JDBC connection.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 10, 2004 2:38 pm 
Beginner
Beginner

Joined: Tue Feb 10, 2004 2:30 pm
Posts: 25
I should add that the tables this would be done on are 1 million plus rows, and the set size anyting from 1 to 50000 in all likelyhood, so reading to a collection, using sets, and then persisting, is potentially way slower than a direct rowset update.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 10, 2004 2:41 pm 
Beginner
Beginner

Joined: Tue Feb 10, 2004 2:30 pm
Posts: 25
thanks for the quick reply.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 10, 2004 2:41 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Thats why this rare case is not the job of ORM (or Hibernate). Use a Stored Procedure or a direct SQL call. If your application is only rare cases, ORM may not be a good choice.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


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