0 Replies Latest reply on Mar 29, 2008 2:02 PM by Andrei Neacsu

    Problem accesing JPA EntityManager from JSP

    Andrei Neacsu Newbie


      I am trying to access an EntityManager from JSP scriptlet for testing purposes and it doesn't work.
      Here is the JSP scriptlet:

      EntityManager em = (EntityManager) (new InitialContext()).lookup("java:comp/env/persistence/em");
      Query query = em.createQuery("select u from USER u");
      List users = (List) query.getResultList();
      for (User user : users) { user.toString(); }

      persistence.xml file :

      <persistence-unit name="myApp">


      web.xml file :


      The application is deployed in JBoss 4.2.2.GA. When I access the JSP page I get the following exception:
      javax.servlet.ServletException: javax.naming.NameNotFoundException: persistence not bound

      I guess I have to configure the resource in jboss-web.xml too, but I don't know how. I tried with <resource-ref>, but I got the same error.

      Any help at all would be highly appreciated !