[jboss-user] [Persistence, JBoss/CMP, Hibernate, Database] - Problem accesing JPA EntityManager from JSP

ensoreus do-not-reply at jboss.com
Sat Mar 29 14:02:20 EDT 2008


Hy,

       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">
		org.hibernate.ejb.HibernatePersistence
  		<jta-data-source>java:/XAOracleDS</jta-data-source>
                
                          
                
</persistence-unit>
......

     web.xml file :

.......
        <persistence-context-ref>
		<persistence-context-ref-name>persistence/em</persistence-context-ref-name>
		<persistence-unit-name>myApp</persistence-unit-name>
	</persistence-context-ref>
.......

    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 !
Thanks.

Andrei
    


View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4139854#4139854

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4139854



More information about the jboss-user mailing list