我在表中有1M行,我想獲得所有這些行。但是,當我試圖通過分頁獲得所有與jpa的行,然後我得到java堆錯誤。你認爲我錯過了什麼嗎?任何意見java持久性內存泄漏
int counter = 0;
while (counter >= 0) {
javax.persistence.EntityManager em = javax.persistence.Persistence
.createEntityManagerFactory("MyPU")
.createEntityManager();
Query query = em.createQuery("select m from mytable m");
java.util.Collection<MyEntity> data = query
.setFirstResult(counter).setMaxResults(1000).getResultList();
for(MyEntity yobj : data){
System.out.println(obj);
}
counter += 1000;
data.clear();
em.clear();
em.close();
}
您是否嘗試使用-Xmx增加堆大小的最大值?請參閱:http://javahowto.blogspot.com/2006/06/6-common-errors-in-setting-java-heap.html – Teetrinker 2011-04-15 10:47:24