3 Replies Latest reply on Feb 26, 2011 6:35 PM by ebross

    Query construction error...

    samwun9988

      Hello,

       

      I am not sure how to implement a query with entityManager.

      I got the following exception when calling the query:

       

      .....

      areEnterpriseApplicationClient.ear/HousewareEnterpriseApplicationClient-ejb.jar/META-INF/wsdl/portal.ixsystems.com.au_80/HousewareEnterpriseApplication1-ejb/RoleWS/RoleWS.wsdl

      2011-02-26 17:49:30,620 ERROR [org.jboss.ejb3.tx2.impl.CMTTxInterceptor] (http-0.0.0.0-80-2) javax.ejb.EJBTransactionRolledbackException: org.hibernate.QueryParameterException: Position beyond number of declared ordinal parameters. Remember that ordinal parameters are 1-based! Position: 1

      2011-02-26 17:49:30,623 ERROR [org.jboss.webservices.integration.invocation.InvocationHandlerEJB3] (http-0.0.0.0-80-2) Method invocation failed with exception: org.hibernate.QueryParameterException: Position beyond number of declared ordinal parameters. Remember that ordinal parameters are 1-based! Position: 1: javax.ejb.EJBTransactionRolledbackException: org.hibernate.QueryParameterException: Position beyond number of declared ordinal parameters. Remember that ordinal parameters are 1-based! Position: 1

       

       

      Here is the Entity class with NamedQuery

       

      @Entity

      @Table(name = "role", catalog = "houseware", schema = "")

      @XmlRootElement

      @NamedQueries({

          @NamedQuery(name = "Role.findAll", query = "SELECT r FROM Role r"),

       

      public class Role implements Serializable {

      ...

       

       

      Here is the Factory class with my query:

       

      public Role findByRoleId(int roleId) {

              Query q = em.createNamedQuery("Role.findByRoleId");

              q.setParameter(1, roleId);

              try {

                return (Role) q.getSingleResult();

              } catch (NoResultException e) {

                return null;

              }

          }

       

       

      Can anyone tell me how to correct this error?

       

      Thanks

      Sam