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

NativeQueryImpl::doScroll seems to be broken when used with setParameterList (affects scroll and stream)

Description

org.hibernate.query.NativeQuery created from org.hibernate.Session::createNativeQuery used with a parameterList and executed with scroll (doScroll) is broken.

scroll/doScroll resolves to doScroll in org.hibernate.query.internal.NativeQueryImpl and it appears it fetches the QueryParameters from AbstractProducedQuery::getQueryParameters first, then at a later stage it expands it in QueryParameterBindingImpl::expandListValuedParameters.

scroll with setParameterList works in HQL but seems to be broken in SQL,

No 1 from *org.hibernate.query.internal.NativeQueryImpl*

1 2 3 4 5 6 7 8 9 @Override protected ScrollableResultsImplementor doScroll(ScrollMode scrollMode) { final QueryParameters queryParameters = getQueryParameters(); queryParameters.setScrollMode( scrollMode ); return getProducer().scroll( generateQuerySpecification(), queryParameters ); }

No 2 from *org.hibernate.query.internal.AbstractProducedQuery*

1 2 3 4 5 6 protected ScrollableResultsImplementor doScroll(ScrollMode scrollMode) { final String query = queryParameterBindings.expandListValuedParameters( getQueryString(), getProducer() ); QueryParameters queryParameters = getQueryParameters(); queryParameters.setScrollMode( scrollMode ); return getProducer().scroll( query, queryParameters ); }

(1) calls getQueryParameters but the expand does not happen until in generareQuerySpecification.
(2) expandListValuedParameters first and afterwards getQueryParameters.

Code have query table/object
User/tUser
Field Long id/bigint iUserId

// WORKS

1 2 3 4 5 6 7 8 final ScrollableResults hqlRes = session.createQuery("select u.id from User u where u.id in (:nos)") .setParameterList("nos", Arrays.asList(64L, 84L)) .scroll(ScrollMode.FORWARD_ONLY); while (hqlRes.next()) { final Object[] p = hqlRes.get(); System.out.println(p[0]); } hqlRes.close();

// BROKEN

1 2 3 4 5 6 7 8 final ScrollableResults sqlRes = session.createNativeQuery("select u.iUserId from tUser u where u.iUserId in (:nos)") .setParameterList("nos", Arrays.asList(64L, 84L)) .scroll(ScrollMode.FORWARD_ONLY); while (sqlRes.next()) { final Object[] p = sqlRes.get(); System.out.println(p[0]); } sqlRes.close();

Results in: Error message: ERROR 2016-08-10 16:12:25,833 org.hibernate.engine.jdbc.spi.SqlExceptionHelper - No value specified for parameter 1.

This affects scroll which is also used in the stream which was added to Query.

Environment

Java 8 (1.8.0_92)
Hibernate 5.2.2
Hibernate-c3p0 5.2.2
mchange c3p0 0.9.5.2
PostgreSQL 9.4.4

Status

Assignee

Andrea Boriero

Reporter

K

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

5.2.2

Priority

Blocker