users@glassfish.java.net

Problem with Persistence Engine : NamedQuery Not Found

From: Sébastien Stormacq <Sebastien.Stormacq_at_Sun.COM>
Date: Fri, 31 Oct 2008 13:28:30 +0100

Hello,

Using GF 2.1 (9.1_02 b04)

I created an Entity Bean and Persistence Unit in an EJB project

When I am calling

em.createNamedQuery("MyEntity.findAll")

from a Stateless EJB (exposed as a Web Service) with a valid query
name, I receive :

java.lang.IllegalArgumentException: NamedQuery of name:
MyEntity.findAll not found.
       at
oracle
.toplink
.essentials
.internal
.ejb.cmp3.base.EJBQueryImpl.getDatabaseQuery(EJBQueryImpl.java:422)
       at
oracle
.toplink
.essentials
.internal
.ejb.cmp3.base.EJBQueryImpl.setAsSQLReadQuery(EJBQueryImpl.java:136)
       at
oracle
.toplink
.essentials
.internal.ejb.cmp3.base.EJBQueryImpl.getResultList(EJBQueryImpl.java:
464)
       at
com.sun.poc.efa.MessageValidation.<init>(MessageValidation.java:61)

Using the exact same code in a POJO, outside of the application server
container works as expected.
The GlassFish version uses JTA while the POJO version uses
RESOURCE_LOCAL

Another issue, probably linked to this one : resource injection is not
working for me :

     @PersistenceContext
     private EntityManager em;

em is null when I first use it.
I worked around by using :

         EntityManagerFactory emf =
Persistence.createEntityManagerFactory("myPU");
         EntityManager em = emf.createEntityManager();
         em.clear();

Any idea ? Thanks


---
Sébastien Stormacq
Senior Software Architect
GSS Software Practice,
Sun Microsystems Luxembourg