Hibernate文档中有一章非常好的关于批处理的章节。
设置属性
hibernate.jdbc.batch_size 20
然后使用此代码
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();更新2015-09-23
我终于找到时间坐下来在https://frightanic.com/software-development/jpa-batch-
inserts/上写了一篇详细的文章。



