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: Hibernate equivalent to PreparedStatement.executeBatch()
PostPosted: Tue Jan 13, 2009 7:58 pm 
Beginner
Beginner

Joined: Wed Sep 21, 2005 11:52 am
Posts: 43
Hibernate version: 3.2
Name and version of the database you are using: DB2 9.5

In my original HIbernate project I wrote some code that explicitly used the Hibernate database connection to execute arbitrary SQL insert statement. I realize that is now deprecated so I am searching for a different way to do it. I know that I can use a Hibernate SQLQuery, but I think the performance may be poor compared to the JDBC version since I was using JDBC batching. For instance:

Code:
PreparedStatement insertSt = conn.prepareStatement("insert into foobar (foo, bar) values (?, ?)");
while (more) {
  insertSt.clearParameters(0;
  insertSt.setString(1, "blah blah");
  insertSt.setString(2, "ha ha");
  if (timeToInsert) {
    insertSt.executeBatch();
    conn.commit();
  }
}


I am inserting ~1.6 million rows, executing the batch every 1000 rows.

Is there some way to do the equivalent in Hibernate? I have looked through the API for SQLQuery and Query and I have read the documentation and one aftermarket book pretty thoroughly, but have not seen anyone discuss this issue.

TIA.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 14, 2009 3:33 am 
Beginner
Beginner

Joined: Wed Nov 19, 2008 8:25 am
Posts: 46
Location: Saint Petersburg, Russian Federation
13. Batch processing


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.