2
OpenJPA是否支持类似于Hibernate的批量插入?我没有在文档中找到它,但我希望我错过了它。我知道JPA doesn't support it in general。OpenJPA是否支持批量插入?
OpenJPA是否支持类似于Hibernate的批量插入?我没有在文档中找到它,但我希望我错过了它。我知道JPA doesn't support it in general。OpenJPA是否支持批量插入?
简短的回答,是的。
较长的答案,请链接到Hibernate文档,并用JPA EntityManager替换Session。
EntityManager em = emf.createEntityManager();
Transaction tx = em.getTransaction();
tx.begin();
for (int i=0; i<100000; i++) {
Customer customer = new Customer(.....);
em.persist(customer);
if (i % 20 == 0) { //20, same as the JDBC batch size
//flush a batch of inserts and release memory:
em.flush();
em.clear();
}
}
tx.commit();
em.close();
我确定一个简单的Google搜索会回答这个问题;也许是“openjpa批量插入”。 – DataNucleus