In my hibernate properties I have
<prop key=”hibernate.jdbc.batch_size”>30</prop>
In my code I do something similar to
final StatelessSession sSession = sessionFactory.openStatelessSession();
try {
sSession.connection().setAutoCommit(false);
} catch (final SQLException se) {
// log a message
}
final Transaction tx = sSession.beginTransaction();
try{
for ( some loop ) {
Customer customer = new Customer(.....);
sSession.insert(customer);
/* Do we need to flush a stateless session? It doesn't have methods for it
if ( i % 30 == 0 ) { //30, same as the JDBC batch size
//flush a batch of inserts and release memory:
sSession.flush();
sSession.clear();
}
*/
}
//sSession.flush();// Do we need to flush a stateless session? It doesn't have methods for it
//sSession.clear();
} finally{
tx.commit();
sSession.close();
}
My Pojo has the following
@Id
//@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "ID", nullable = false, unique = true)
private Long id;
However, When I change the batch size it doesn’t seem to affect the overall run time. How can I verify that it is in fact working?
Thanks!
comment out
session.flush();and see if anything is inserted after 20 loop interationsUpdate: to the updated question
commenting
//@GeneratedValue(strategy = GenerationType.AUTO)should fall back to default which is AFAIK Identitytry using