我有以下方法:關閉的EntityManager org.datanucleus.exceptions.NucleusUserException
public List<Profile> listProfiles(){
EntityManager em = EMF.get().createEntityManager();
List<Profile> list = null;
try{
Query q = em.createQuery("SELECT p FROM Profile p");
list = (List<Profile>)q.getResultList();
} catch(NoResultException ex){
System.out.println("ERROR CATCHED: " + ex.getMessage());
} finally{
em.close();
}
return list;
}
訪問返回列表將拋出一個錯誤: org.datanucleus.exceptions.NucleusUserException: Object Manager has been closed
一招,我發現是添加則爲list.size ()在關閉實體經理之前:
finally{
list.size();
em.close();
}
我應該關閉實體經理嗎?還是有我錯過的概念?其他
是使用''前'em.close則爲list.size()()'好嗎? –