| Hi, I am sorry if I am mistaken, but don't you think there is a bit confused behaviour in Batch Processing section - https://docs.jboss.org/hibernate/orm/4.0/devguide/en-US/html/ch04.html (4.1. Batch inserts) or in previous or current hibernate doc versions. for (int i = 0; i < 100; i++) { System.out.println("Save new object " + i); if (i % 20 == 0) { System.out.println("flush and clear " + i); } } Save new object 0 flush and clear 0 Save new object (1-20) flush and clear 20 Save new object (21-40) flush and clear 40 Save new object (41-60) flush and clear 60 Save new object (61-80) flush and clear 80 Save new object (81-99) and as you can see that first flush is occurred when first row has been saved, cause when i=0 (i % 20 == 0) -> true. As for me it should be: int batchSize = 0; for (int i = 0; i < 100; i++) { System.out.println("Save new object " + i); if (++batchSize % 20 == 0) { System.out.println("flush and clear " + i); } } Save new object (0-19) flush and clear 19 Save new object (20-39) flush and clear 39 Save new object (40-59) flush and clear 59 Save new object (60-79) flush and clear 79 Save new object (80-99) Here we see that first flush is occurred exactly after 20 rows have been saved. This result many people expect and this example is clearer than first one. |