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