-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 
Author Message
 Post subject: Numbering positional parameters from zero fails
PostPosted: Mon Oct 03, 2005 9:33 pm 
Newbie

Joined: Fri Aug 13, 2004 12:49 pm
Posts: 10
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.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 05, 2005 9:01 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
It's a mistake in the doc, In the EJB3 spec 4.6.4.1 Input parameters are numbered starting from 1.

So Oracle impl is wrong and Hibernate EntityManager doc is wrong

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 05, 2005 10:08 am 
Newbie

Joined: Fri Aug 13, 2004 12:49 pm
Posts: 10
Thanks for the clarification. When in doubt follow the specification :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.