public boolean removeBalance(long id) {
EntityManager em = EMFService.get().createEntityManager();
try {
Balance balance = em.find(Balance.class, id);
if (balance!= null) {
em.getTransaction().begin();
em.remove(balance);
List<Balance> listBalance=listBalance(balance.getUrut());
for(int i=0;i<listBalance.size();i++){
//update some entity
}
em.getTransaction().commit();
return true;
} else {
return false;
}
} catch (Exception e) {
em.getTransaction().rollback();
e.printStackTrace();
return false;
} finally {
em.close();
}
}
log只显示:
2013-04-19 23:33:56.980 (link here) 200 259ms 20kb Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31
139.0.82.222 - - [19/Apr/2013:09:33:56 -0700] "POST
我在代码中犯了错误吗?
更新:
如果在事务中更新超过5条记录,它就无法正常工作,感谢@DataNucleus注意到它是Google App Engine的限制。