这是 Hibernate 关于批处理的代码示例:
Session session = sessionFactory.openSession();
Transaction tx = session.beginTransaction();
for ( int i=0; i<100000; i++ ) {
Customer customer = new Customer(.....);
session.save(customer);
if ( i % 20 == 0 ) { //20, same as the JDBC batch size
//flush a batch of inserts and release memory:
session.flush();
session.clear();
}
}
tx.commit();
session.close();
在代码的开头,它使用.openSession()
但是,当我编写代码时,我使用getCurreentSession()
. 似乎它会产生org.hibernate.TransactionException: nested transactions not supported
错误。
谁能解释为什么会这样?