Can some one explain me how
hibernate.jdbc.batch_size=1000
and
if (i % 100 == 0 && i>0) {
Batch Processing allows you to group related SQL statements into a batch and submit them with one call to the database.
Why we need
It is important to keep in mind, that each update added to a Statement or PreparedStatement is executed separately by the database. That means, that some of them may succeed before one of them fails. All the statements that have succeeded are now applied to the database, but the rest of the updates may not be. This can result in an inconsistent data in the database.
To avoid this, you can execute the batch update inside a transaction. When executed inside a transaction you can make sure that either all updates are executed, or none are. Any successful updates can be rolled back, in case one of the updates fail.
What is Batch and Flushing
Batch size and flushing is different thing. when you set hibernate.jdbc.batch_size
to 1000
it means hibernate will do batch inserts or update upto 1000
entities.flush
operation can be used the write all changes to the database before the transaction is committed
if your batch size is set to 1000, and you flush every 100 entity, Hibernate will execute lots of small batches of 100 insert or update statements for 10 times.
Please read more below this link:
http://docs.jboss.org/hibernate/orm/3.3/reference/en/html/batch.html
Why number of objects being flushed should be equal to hibernate.jdbc.batch_size?