[hibernate-issues] [Hibernate-JIRA] Created: (EJB-214) Native Query can not be used with parameter

Shinpei Ohtani (JIRA) noreply at atlassian.com
Tue Aug 15 03:51:18 EDT 2006


Native Query can not be used with parameter
-------------------------------------------

         Key: EJB-214
         URL: http://opensource.atlassian.com/projects/hibernate/browse/EJB-214
     Project: Hibernate Entity Manager
        Type: Bug

  Components: EntityManager  
    Versions: 3.2.0.cr1    
 Environment: Hibernate EntityManager 3.2.0.cr1
Hibernate Core 3.2.0 cr2
    Reporter: Shinpei Ohtani



When using Native Query with parameter, IndexOutOfBoundsException is occurred.
org.hibernate.engine.query.ParameterParser(Hibernate Core) handles positional parameter as named parameter internally,
but org.hibernate.ejb.QueryImpl(Hibernate EntityManager) expects positional(ordinal) parameter, not named parameter.

Here is sample for this issue.
=======
Query query = em.createNativeQuery("SELECT d.name FROM Department d WHERE d.id = ?1");
query.setParameter(1, 1);
=======

Result is
java.lang.IndexOutOfBoundsException: Remember that ordinal parameters are 1-based!
       at org.hibernate.engine.query.ParameterMetadata.getOrdinalParameterDescriptor(ParameterMetadata.java:55)
       at org.hibernate.engine.query.ParameterMetadata.getOrdinalParameterExpectedType(ParameterMetadata.java:61)
       at org.hibernate.impl.AbstractQueryImpl.determineType(AbstractQueryImpl.java:389)
       at org.hibernate.impl.AbstractQueryImpl.setParameter(AbstractQueryImpl.java:369)
       at org.hibernate.ejb.QueryImpl.setParameter(QueryImpl.java:198)



-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira




More information about the hibernate-issues mailing list