[hibernate-issues] [Hibernate-JIRA] Commented: (EJB-214) Native Query can not be used with parameter
Shinpei Ohtani (JIRA)
noreply at atlassian.com
Wed Aug 30 08:19:24 EDT 2006
[ http://opensource.atlassian.com/projects/hibernate/browse/EJB-214?page=comments#action_24229 ]
Shinpei Ohtani commented on EJB-214:
------------------------------------
I tried recent svn(revision:10375) and still failed.
So I created one test to org.hibernate.ejb.test.QueryTest.
That is:
public void testNativeQueryWithParameter() {
Item item = new Item("Mouse", "Micro$oft mouse");
EntityManager em = factory.createEntityManager();
em.getTransaction().begin();
em.persist(item);
assertTrue(em.contains(item));
em.getTransaction().commit();
em.getTransaction().begin();
Query query = em.createNativeQuery("select * from Item where name = ?1", Item.class);
query.setParameter(1, "Mouse");
item = (Item) query.getSingleResult();
assertNotNull(item);
assertEquals("Micro$oft mouse", item.getDescr());
em.remove(item);
em.getTransaction().commit();
em.close();
}
I suppose this test will fail(at least my environment).
Could you try this?
Thanks in advance.
> 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