I have been trying to understand the significance of the parameter hibernate.jdbc.batch_size. The following code works well even without mentioning the hibernate.jdbc.batch_size parameter in the configuration.
Code:
{
Session session = HibernateSessionFactory.getSession();
session.beginTransaction();
for(int i=0; i<20; i++) {
Address address = new Address();
address.setAddressArea("Add - " + i);
session.save(address);
if (i==5) {
System.out.println("Flushing Session...");
session.flush();
session.clear();
System.out.println("Session Flushed");
SessionStatistics sessionStatistics =session.getStatistics();
System.out.println(sessionStatistics.getEntityCount());
// Load address - Must be a DB Hit
Address testAddress = (Address)session.get(Address.class, new Long(i));
System.out.println(testAddress.getAddressArea());
}
}
session.getTransaction().commit();
}
In the above code, the session is flushed at
Code:
if (i==5)
When I retrieve the Address object at
Code:
Address testAddress = (Address)session.get(Address.class, new Long(i));
, it makes a DB hit and fetches the address object that was flushed. Everything is working fine as expected, so why do i need to set the parameter
hibernate.jdbc.batch_size and flush the session only when the number of objects saved in session equals to the batch size. Apparently, the batch code above works fine even without configuring the hibernate.jdbc.batch_size parameter.
I am unable to undertand the significance of the parameter hibernate.jdbc.batch_size. Can anyone throw some light?