title: Moving Hibernate app to JBoss - Position beyond number of declared ordinal parameters
body: <p>i have a Hibernate web app that is currently working on tomcat/CloudFoundry, but when i try to run it on JBoss I am getting some errors.</p>
  
  <p>In my DAO I am creating a query to load Users by userName, as follows:</p>
  
  <pre><code>Query query = getEntityManager().createQuery("select u from com.tmm.enterprise.socialcv.security.Account u where u.userName = ?1");
  query.setParameter(1, userName);
  </code></pre>
  
  <p>The above works when I run the app on Tomcat, but when I run it on JBoss I get the following error:</p>
  
  <pre><code>16:31:47,639 DEBUG [org.springframework.web.servlet.DispatcherServlet] (http-localhost-127.0.0.1-8080-1) Handler execution resulted in exception - forwarding to resolved error view: ModelAndView: reference to view with name 'dataAccessFailure'; model is {exception=org.springframework.dao.InvalidDataAccessApiUsageException: org.hibernate.QueryParameterException: Position beyond number of declared ordinal parameters. Remember that ordinal parameters are 1-based! Position: 1; nested exception is java.lang.IllegalArgumentException: org.hibernate.QueryParameterException: Position beyond number of declared ordinal parameters. Remember that ordinal parameters are 1-based! Position: 1}: org.springframework.dao.InvalidDataAccessApiUsageException: org.hibernate.QueryParameterException: Position beyond number of declared ordinal parameters. Remember that ordinal parameters are 1-based! Position: 1; nested exception is java.lang.IllegalArgumentException: org.hibernate.QueryParameterException: Position beyond number of declared ordinal parameters. Remember that ordinal parameters are 1-based! Position: 1
      at org.springframework.orm.jpa.EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(EntityManagerFactoryUtils.java:301) [org.springframework.orm-3.1.1.RELEASE.jar:3.1.1.RELEASE]
      at org.springframework.orm.jpa.aspectj.JpaExceptionTranslatorAspect.ajc$afterThrowing$org_springframework_orm_jpa_aspectj_JpaExceptionTranslatorAspect$1$18a1ac9(JpaExceptionTranslatorAspect.aj:15) [spring-aspects-3.1.1.RELEASE.jar:3.1.1.RELEASE]
      at com.tmm.enterprise.socialcv.security.dao.AccountDAO.loadAccountByUserName(AccountDAO.java:28) [classes:]
      at com.tmm.enterprise.socialcv.service.AccountService.loadAccountByUserName(AccountService.java:48) [classes:]
      at com.tmm.enterprise.socialcv.service.AccountService.setCredentials(AccountService.java:241) [classes:]
      at com.tmm.enterprise.socialcv.controller.HomeController.signup(HomeController.java:59) [classes:]
      ...
  Caused by: java.lang.IllegalArgumentException: org.hibernate.QueryParameterException: Position beyond number of declared ordinal parameters. Remember that ordinal parameters are 1-based! Position: 1
      at org.hibernate.ejb.QueryImpl.setParameter(QueryImpl.java:446) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final]
      at org.hibernate.ejb.QueryImpl.setParameter(QueryImpl.java:67) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final]
      ... 80 more
  Caused by: org.hibernate.QueryParameterException: ***Position beyond number of declared ordinal parameters. Remember that ordinal parameters are 1-based! Position: 1***
      at org.hibernate.engine.query.spi.ParameterMetadata.getOrdinalParameterDescriptor(ParameterMetadata.java:80) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
      at org.hibernate.engine.query.spi.ParameterMetadata.getOrdinalParameterExpectedType(ParameterMetadata.java:86) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
      at org.hibernate.internal.AbstractQueryImpl.determineType(AbstractQueryImpl.java:444) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
      at org.hibernate.internal.AbstractQueryImpl.setParameter(AbstractQueryImpl.java:416) [hibernate-core-4.0.1.Final.jar:4.0.1.Final]
      at org.hibernate.ejb.QueryImpl.setParameter(QueryImpl.java:440) [hibernate-entitymanager-4.0.1.Final.jar:4.0.1.Final]
      ... 81 more
  </code></pre>
  
  <p>I have tried changing to both the following queries but still no luck:</p>
  
  <pre><code>Query query = getEntityManager().createQuery("select u from com.tmm.enterprise.socialcv.security.Account u where u.userName = ?");
          query.setParameter(0, userName);
  </code></pre>
  
  <p>The above gives me the same error. As does:</p>
  
  <pre><code>Query query = getEntityManager().createQuery("select u from com.tmm.enterprise.socialcv.security.Account u where u.userName = ?");
          query.setParameter(1, userName);
  </code></pre>
  
  <p>And switching to named parameters gives me an error about not being able to locate named parameter.</p>
  
  <p>Any ideas? (as an aside, I also had to update the DAO to fully qualified Account in the query on JBoss - on tomcat it was working just querying Account)</p>