Issue Type: Bug Bug
Affects Versions: 4.1.8
Assignee: Unassigned
Components: query-hql
Created: 16/Feb/13 11:02 AM
Description:

The JPA spec doesn't state that JPQL positional parameters must be a sequence.

Hibernate in case when they are not, e.g.

SELECT foo FROM Foo foo WHERE foo IN (?1, ?3)

throws

java.lang.IllegalArgumentException: org.hibernate.QueryParameterException: Position beyond number of declared ordinal parameters. Remember that ordinal parameters are 1-based! Position: 4

This is user-unfriendly when the JPQL is constructed with conditions and loops. I think that it's rational to expect the following to work.

return this.em.createQuery("SELECT ma FROM MavenArtifact ma "
                + " WHERE ma.groupId  = ?1"
                + " AND ma.artifactId = ?2"
                + " AND ma.version    = ?3"
                + " AND (" + packCond + ") "
                + " AND ma.classifier = ?5"
                , MavenArtifact.class)
                .setParameter(1, groupId)
                .setParameter(2, artifactId)
                .setParameter(3, version)
                .setParameter(4, packaging)
                .setParameter(5, classifier)
                .getSingleResult();
Project: Hibernate ORM
Labels: positional-parameters
Priority: Major Major
Reporter: Ondra Žižka
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira