Hibernate version:
3.1 beta 3
Annotations 3.1 beta 5
EntityManager 3.1 beta 3
Code between sessionFactory.openSession() and session.close():
Code:
EntityManagerFactory emf = Persistence.createEntityManagerFactory("BeerDistributor");
EntityManager em = emf.getEntityManager();
em.getTransaction().begin();
Long id = new Long(2);
Beer b = (Beer)em.createQuery(
"select object(o) from Beer o where o.id = ?")
.setParameter(0, id)
.getSingleResult();
em.getTransaction().commit();
Full stack trace of any exception that occurs:
Exception in thread "main" java.lang.IllegalArgumentException: Positional parameter does not exist: -1 in query: select object(o) from Beer o where o.id = ?
at org.hibernate.impl.AbstractQueryImpl.setParameter(AbstractQueryImpl.java:212)
at org.hibernate.impl.AbstractQueryImpl.setParameter(AbstractQueryImpl.java:456)
at org.hibernate.ejb.QueryImpl.setParameter(QueryImpl.java:158)
at com.mycompany.jpa.TestEJB3.main(TestEJB3.java:30)
It seems to work if I specify a 1 as the index but that is not consistent with the EntityManager reference documentation - Section 3.4.1.3. Bind parameters -- "Contrary to JDBC, The EJB3 specification numbers positional parameters from zero, not one." Also, Oracle's implementation uses a zero-based index.