本文介绍了OpenJPA是否支持批量插入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
OpenJPA是否对批处理插入提供任何支持,类似于休眠?我尚未在文档中找到它,但我希望我能错过它.我知道 JPA通常不支持.
Does OpenJPA have any support for batch insert similar to Hibernate? I haven't found it in the docs, but I'm hoping I missed it. I know JPA doesn't support it in general.
推荐答案
答案很简单,是的.
更长的答案,请转到Hibernate文档的链接,然后将会话替换为JPA EntityManager.
Longer answer, take the link to Hibernate documentation and replace the Session with a JPA EntityManager.
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();
这篇关于OpenJPA是否支持批量插入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!