最佳答案
为了节省内存,您必须确保定期清除会话,所以
Customer.em().getTransaction().begin(); for ( int i=1; i<=100000; i++ ) { .... myCustomer.save(); if (i%1000==0) { //Customer.em().getTransaction().commit(); Customer.em().flush(); Customer.em().clear(); //Customer.em().getTransaction().begin(); } } Customer.em().getTransaction().commit();
@H_301_16@如果优化批量大小,如何提高性能
hibernate.jdbc.batch_size 100你可以简单地将最后一行添加到application.conf,所有hibernate.*属性直接转到hibernate.有关详细信息,请参阅JPAPlugin的代码.