We're updating the issue view to help you get more done. 

Confused batch processing doc example

Description

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.

Environment

None

Status

Assignee

Unassigned

Reporter

Igor Dmitriev

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

5.1.2

Priority

Trivial