2 Replies Latest reply on May 30, 2013 6:31 PM by Scott Marlow

    NamedQuery not found with EclipseLink

    William Lovett Newbie



      I'm using EAP 6.1 and JDeveloper 11g.  The project deploys successfully but when I open the first page (which queries for some users), I receive the following error:


      17:11:31,564 ERROR [stderr] (http- java.lang.IllegalArgumentException: NamedQuery of name: ReUniquePerson.findByOidUid not found.
      17:11:31,566 ERROR [stderr] (http-           at org.eclipse.persistence.internal.jpa.QueryImpl.getDatabaseQueryInternal(QueryImpl.java:323)
      17:11:31,566 ERROR [stderr] (http-           at org.eclipse.persistence.internal.jpa.EntityManagerImpl.createNamedQuery(EntityManagerImpl.java:1061)
      17:11:31,566 ERROR [stderr] (http-           at org.jboss.as.jpa.container.AbstractEntityManager.createNamedQuery(AbstractEntityManager.java:356)
      17:11:31,567 ERROR [stderr] (http-           at myManagerBean.queryReUniquePersonFindByOidUid(P2mcManagerBean.java:126)


      It seems that JBoss isn't seeing my persistence entities.



          <persistence-unit name="MYORG" transaction-type="JTA">
                  <property name="eclipselink.weaving" value="false"/>
                  <property name="eclipselink.weaving.lazy" value="false"/>
                  <property name="eclipselink.weaving.fetchgroups" value="false"/>
                  <property name="eclipselink.weaving.changetracking" value="false"/>
                  <property name="eclipselink.target-server" value="JBoss"/>
                  <property name="eclipselink.target-database" value="ORACLE"/>
                  <property name="eclipselink.cache.size.default" value="1000"/>
                  <property name="eclipselink.cache.type.default" value="SoftWeak"/>
                  <property name="eclipselink.cache.shared.default" value="false"/>
                  <property name="eclipselink.jdbc.batch-writing" value="Oracle-JDBC"/>
                  <property name="eclipselink.logging.level" value="CONFIG"/>


      Here's the sequence:


      I call the first page, which instantiages the backing bean.  The backing bean, upon creation, grabs the entity manager successfully.

      public class UserManager{
           // backing bean constructor calls entity manager session bean
           public UserManager{
                       System.out.println("Querying " + userId);
                       ReUniquePerson userSearch = em.queryReUniquePersonFindByOidUid(userId);


      The entity manager then fires off the queryReUniquePersonFindByOidUid method.  However, there is an error creating the named query.


      Session Bean


      @Stateless(name = "MyManager")
      MyManagerBean implements MyManager, MyManagerLocal {
          @PersistenceContext(unitName = "Model")
          private EntityManager em;
      public ReUniquePerson queryReUniquePersonFindByOidUid(Object oidUid) {
              try {
                  System.out.println("Creating named query");
                  Query query = em.createNamedQuery("ReUniquePerson.findByOidUid");
                  query = query.setParameter("oidUid",oidUid);
                  System.out.println("Querying for person");
                  Object obj = query.getSingleResult();
                  System.out.println("Found " + obj);
                  return (ReUniquePerson) obj;
              } catch (Exception e) {
                  if (debug == true) {
                  return null;


      Here's the Entity ReUniquePerson.java


                     @NamedQuery(name = "ReUniquePerson.findByOidUid", query = "select o from ReUniquePerson o where UPPER(o.oidUid) = UPPER(:oidUid)"),
                     @NamedQuery(name = "ReUniquePerson.findByLastname", query = "select o from ReUniquePerson o where UPPER(o.lname) LIKE UPPER(:lname)")})
      @Table(name = "RE_UNIQUE_PERSON")
      public class ReUniquePerson implements Serializable {


      My WAR structure is as follows.  I apologize in advance for my poor ascii art



           |----      .jspx's
           |----     WEB-INF
                     |---  classes
                     |          |--- META-INF
                     |          |          |--- persistence.xml
                     |          |          |--- ejb-jar.xml
                     |          |          |--- adf-settings.xml
                     |          |--- com.sample.ReUniquePerson
                     |--- lib
                     |       |--- A whole lotta jars
                     |--- faces-config.xml
                     |--- web.xml
                     |--- other xml files



      I have tried https://community.jboss.org/wiki/HowToUseEclipseLinkWithAS7 but it does not appear that JBoss automatically picks up my use of EclipseLink.  If I do not include my own jars in my lib directory, the program does not deploy.  To get around this, I package all my persistence files in my lib directory.  Those are





      Any ideas?