0

I have the method below:

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;
}

Accessing the return list will throw an error: org.datanucleus.exceptions.NucleusUserException: Object Manager has been closed

One trick I found is to add list.size() before closing entity manager:

finally{
    list.size();
    em.close(); 
}

Should I close entity manager? Or are there concepts I missed?

4

1 回答 1

0

另一个“概念”是使用 GAE JPA 插件的 v2。它是很久以前发布的。

于 2012-06-29T06:17:44.533 回答