[
http://opensource.atlassian.com/projects/hibernate/browse/HHH-5360?page=c...
]
Koen Verrecken commented on HHH-5360:
-------------------------------------
Nice, that will do the job. Is there a reason why this is not the default behaviour?
Also, I did a search on google for this property and only found similar articles and forum
threads about people having the same problem. Perhaps it would be nice to add this to the
hibernate documentation in Chapter 13. Batch processing
Poor batch insert performance when inserting different objects
--------------------------------------------------------------
Key: HHH-5360
URL:
http://opensource.atlassian.com/projects/hibernate/browse/HHH-5360
Project: Hibernate Core
Issue Type: Improvement
Components: core
Affects Versions: 3.3.2
Reporter: Koen Verrecken
Batch insert works nicely when you only have one object to insert:
for (int i = 0; i < 20; i++) {
Book book = new Book();
dao.save(book);
}
Provided that the batch size in Hibernate is set to 20, Hibernate will correctly batch up
to 20 insert statements and execute the batch at the end.
However, the following code example gives a different result:
for (int i = 0; i < 20; i++) {
Book book = new Book();
Author author = new Author();
dao.save(book);
dao.save(author);
}
In this case Hibernate will execute every single insert as a separate batch query. The
result is 40 different insert statements fired at the database instead of 2.
In the org.hibernate.jdbc.AbstractBatcher class I found a probable reason for this
behaviour. The prepareBatchStatement method checks if the current sql is the same as the
sql of the previous statement. If so, the previous prepared statement will be reused.
This is never the case for my 2nd example above, where Hibernate continuously switches
between "insert into Book..." and "insert into Author" statements.
Would it be possible to cache more than one prepared statement?
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://opensource.atlassian.com/projects/hibernate/secure/Administrators....
-
For more information on JIRA, see:
http://www.atlassian.com/software/jira