[hibernate-issues] [Hibernate-JIRA] Commented: (EJB-214) Native Query can not be used with parameter
Steve Ebersole (JIRA)
noreply at atlassian.com
Thu Aug 31 06:34:24 EDT 2006
[ http://opensource.atlassian.com/projects/hibernate/browse/EJB-214?page=comments#action_24249 ]
Steve Ebersole commented on EJB-214:
------------------------------------
We should really consider disallowing mixing ordinal and named parameters in core. Then you could rely on the query parameter metadata...
> 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