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

Emmanuel Bernard (JIRA) noreply at atlassian.com
Wed Aug 30 21:39:24 EDT 2006


     [ http://opensource.atlassian.com/projects/hibernate/browse/EJB-214?page=all ]
     
Emmanuel Bernard resolved EJB-214:
----------------------------------

    Resolution: Fixed

fixed but the algorithm is weak, since I check for '?' and the following char

> 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
>     Assignee: Emmanuel Bernard
>      Fix For: 3.2.0.cr2

>
>
> 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