Hi
I use Google App Engine with datanucleus and JPA. I'm having a real hard time grasping how I'm supposed to read stuff from data store and pass it to JSP. If I load a list of POJOs with entitymanager and pass it to JSP, it crashes to org.datanucleus.exceptions.NucleusUserException: Object Manager has been closed.
I understand why this is happening. Obviously because I fetch the list, close the entity manager and pass it to JSP, at which point it will fail because the list is lazy. How do I make the list NOT lazy without resorting to hacks like calling size() or something like that?
Here is what I'm trying to do:
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setAttribute("parties", getParties());
RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/WEB-INF/parties.jsp");
dispatcher.forward(req, resp);
}
private List<Party> getParties(){
EntityManager em = entityManagerProvider.get();
try{
Query query = em.createQuery("SELECT p FROM Party p");
return query.getResultList();
}finally{
em.close();
}
}