3 Replies Latest reply on Feb 23, 2006 10:09 AM by wesslan

    @NamedQuery in JBoss 4.0.4

    pimpf

      Hi there,
      Does anyone know if @NamedQuery is supported in JBoss 4.0.4 RC1?

      I defined one as:

      @Entity(name="Customer")
      @Table(name="CUSTOMERS")
      @NamedQuery(name="findAllCustomers", query="SELECT c FROM Customers c")
      public class Customer implements Serializable {
      private Long addressId;
      private Long customerId;
      private String firstName;


      In stateless session bean I called it like this:

      @PersistenceContext(unitName="my-persistence")
      protected EntityManager em;

      public List findAllCustomers() {
      return em.createNamedQuery("findAllCustomers").getResultList();
      }


      and at the end when tried to deployed I received this:

      2006-02-23 15:47:51,637 DEBUG [org.hibernate.hql.ast.QueryTranslatorImpl] parse() - HQL: SELECT c FROM Customers c

      2006-02-23 15:47:51,637 DEBUG [org.hibernate.hql.ast.AST] --- HQL AST ---

      \-[QUERY] 'query'

      \-[SELECT_FROM] 'SELECT_FROM'

      +-[FROM] 'FROM'

      | \-[RANGE] 'RANGE'

      | +-[IDENT] 'Customers'

      | \-[ALIAS] 'c'

      \-[SELECT] 'SELECT'

      \-[IDENT] 'c'



      2006-02-23 15:47:51,637 DEBUG [org.hibernate.hql.ast.ErrorCounter] throwQueryException() : no errors

      2006-02-23 15:47:51,637 DEBUG [org.hibernate.hql.antlr.HqlSqlBaseWalker] select << begin [level=1, statement=select]

      2006-02-23 15:47:51,637 DEBUG [org.jboss.mx.loading.UnifiedClassLoader] New jmx UCL with url null

      2006-02-23 15:47:51,637 DEBUG [org.jboss.mx.loading.RepositoryClassLoader] setRepository, repository=org.jboss.mx.loading.HeirarchicalLoaderRepository3@1fef1a0, cl=org.jboss.mx.loading.UnifiedClassLoader3@966110{ url=null ,addedOrder=0}

      2006-02-23 15:47:51,637 DEBUG [org.hibernate.impl.SessionFactoryImpl] Checking 0 named SQL queries

      2006-02-23 15:47:51,637 ERROR [org.hibernate.impl.SessionFactoryImpl] Error in named query: findAllCustomers

      org.hibernate.hql.ast.QuerySyntaxException: Customers is not mapped. [SELECT c FROM Customers c]

      at org.hibernate.hql.ast.util.SessionFactoryHelper.requireClassPersister(SessionFactoryHelper.java:157)

      at org.hibernate.hql.ast.tree.FromElementFactory.addFromElement(FromElementFactory.java:86)

      at org.hibernate.hql.ast.tree.FromClause.addFromElement(FromClause.java:70)

      at org.hibernate.hql.ast.HqlSqlWalker.createFromElement(HqlSqlWalker.java:263)

      at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElement(HqlSqlBaseWalker.java:3049)

      at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromElementList(HqlSqlBaseWalker.java:2938)

      at org.hibernate.hql.antlr.HqlSqlBaseWalker.fromClause(HqlSqlBaseWalker.java:688)

      at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:544)

      at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:281)



      and in ear file I had persistence.xml with:



      <persistence-unit name="my-persistence">
      <jta-data-source>java:/MyDS</jta-data-source>

      <!-- additional properties - can include hibernate properties here -->

      </persistence-unit>



      Can anyone see where the problem is and if @NamedQuery is supported?

      Thx!

        • 1. Re: @NamedQuery in JBoss 4.0.4
          wesslan

          Your query is "SELECT c FROM Customers c" but your entity is named Customer (without the s on the end).
          Your query should be "SELECT c FROM Customer c".

          Regards Peter

          • 2. Re: @NamedQuery in JBoss 4.0.4
            pimpf

             

            "wesslan" wrote:
            Your query is "SELECT c FROM Customers c" but your entity is named Customer (without the s on the end).
            Your query should be "SELECT c FROM Customer c".

            Regards Peter



            I can't believe this, I played around with so many scenarios and at the end - I didn't see a 's'.
            Cheers mate!

            • 3. Re: @NamedQuery in JBoss 4.0.4
              wesslan

               

              "pimpf" wrote:
              I can't believe this, I played around with so many scenarios and at the end - I didn't see a 's'.
              Cheers mate!


              Welcome to the club! :-)