В моих свойствах гибернации у меня есть ‹prop key="hibernate.jdbc.batch_size">30‹/prop>
В моем коде я делаю что-то похожее на
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();
}
Мой Pojo имеет следующее
@Id
//@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "ID", nullable = false, unique = true)
private Long id;
Однако, когда я изменяю размер партии, это, похоже, не влияет на общее время выполнения. Как я могу убедиться, что он действительно работает?
Спасибо!