We're updating the issue view to help you get more done. 

NamedNativeQueries ordinal parameters are zero based

Description

This bug is the same as HHH-10885, except for NamedQueries and NamedNativeQueries instead of NativeQueries

The problem is that the position (ordinal paramer) in Query.setParameter(int, Object) is zero based. JPA 2.1 spec states that the ordinal parameters should be 1-based.

This works (but shouldn't)

1 2 3 Query query = entityManager.createNamedQuery("MyQuery"); query.setParameter(0, "MyParameter"); List list = query.getResultList();

This causes IllegalArgumentExceptions , but should work

1 2 3 Query query = entityManager.createNamedQuery("MyQuery"); query.setParameter(1, "MyParameter"); List list = query.getResultList();

A workaround is to use specific positions in the statement (e.g. ... where id = ?1 instead of ... where id = ? )

Arquillian test case is attached (can be run with mvn verify )

I believe this affects all Hibernate 5 versions (tested with 5.1.0.Final, 5.2.0.Final and 5.2.2.Final)

Environment

Java 1.8.0_74
Hibernate 5.2.2.Final
OSX 10.9 / Windows 7

Status

Assignee

Andrea Boriero

Reporter

Jerrimiah Nance

Fix versions

Labels

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Affects versions

5.2.0

Priority

Critical