Technology stack: Oracle database 11.2.0.2, Java 1.6, Hibernate 3.6.6.Final.
I am new to hibernate, apologize if this is trivial.
The following code was supposed to put some optimization:
Transaction tx = session.beginTransaction();
for (int i = 0; i < 10; i++) {
POJO pojo = new POJO(i);
session.save(pojo);
}
tx.commit();
hibernate.cfg.xml
has the following entry
<property name="jdbc.batch_size">500</property>
How can I verify, if hibernate really batches all these inserts? If it performs 10 inserts than there is no gain.
One idea is to put the jdbc plain query right after save()
that checks if the record was added to db:
String query = "retrieve previously added element"
PreparedStatement stmt = session.connection().prepareStatement(query.toString());
Result rs = statement.executeQuery();
/** check contents of rs */
In my case it returns a non empty set with previously added element. Does it mean anything? How else can I check if batching works.
thanks in advance
You need to add "BatchingBatch" logger to your logging provider.
org.hibernate.engine.jdbc.batch.internal.BatchingBatch
Than you will be able to see in the logs something like:
2018-02-20 17:33:41.279 DEBUG 6280 --- [ main] o.h.e.jdbc.batch.internal.BatchingBatch : Executing batch size: 19
Unless you see this message,batching is not working.
Tested with Hibernate Version:5.2.12