2012-05-23 68 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();