2012-05-23 72 views

回答

4

简短的回答,是的。

较长的答案,请链接到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();