| The problem seems related with the execution of the same query string once with EntityManager#createNativeQuery and another with Session#createSQLQuery. The ParameterMetadataImpl is cached by QueryPlanCache the first time EntityManager#createNativeQuery is executed with isZeroBasedParametersIndex value to true, when the Session#createSQLQuery. is executed the ParameterMetadataImpl is retrieved from the QueryPlanCache with the wrong value of isZeroBasedParametersIndex. So
NativeQueryImplementor query = (NativeQueryImplementor) em.createNativeQuery( sqlString );
query.setLong(1, page.getId());
List list = query.list();
NativeQuery sqlQuery sqlQuery = em.unwrap( Session.class ).createSQLQuery( sqlString );
sqlQuery.setLong(1, page.getId());
List results results = sqlQuery.list();
|