Mysql hibernate batch insert / update
We are using container managed transaction. JBOSS AS7 Application Server. I have included the following properties in hibernate config file
<property name="hibernate.connection.url">jdbc:mysql://localhost/test?rewriteBatchedStatements=true</property>
<property name="hibernate.jdbc.batch_size" value="20"/>
<property name="hibernate.order_inserts" value="true"/>
<property name="hibernate.order_updates" value="true"/>
<property name="hibernate.jdbc.batch_versioned_data" value="true"/>
And included the logging property below
<logger category="org.hibernate.SQL">
<level name="TRACE"/>
</logger>
I am inserting 10 records into a database. In hibernate.log, I could see 10 insert statements as below
org.hibernate.sql insert into test (name,value,date) values (?,?,?) org.hibernate.sql insert into test (name,value,date) values (?,?,?)
Package insert not working
source to share
You may actually be using batch processing; it's just that Hibernate prints a separate sql for each entity instance.
To test this, turn on the DEBUG log level for the package org.hibernate
(and the TRACE level for org.hibernate.type
if you want to see associated variables), then check if the following phrases appear in the log:
-
Batch Operator Reuse
-
Batch size execution
If a number greater than 1 is printed for the batch size executed, you are using batch processing.
MySQL-specific, to make sure the MySQL driver overwrites insert statements, include the parameter profileSQL
in the connection url as described here .
NOTE. JDBC batching is disabled when using the IDTITITY id generator.
source to share