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

Wrong NativeQueryImpl.setZeroBasedParametersIndex when Session#createSQLQuery is executed after EM#createNativeQuery

Description

Calling EntityManager.createNativeQuery calls NativeQueryImpl.setZeroBasedParametersIndex, which in turn calls ParameterMetadataImpl.setOrdinalParametersZeroBased(false). ParameterMetadataImpl is shared between threads for all sessions, and so one thread is getting the 'true' version of isZeroBasedParametersIndex(). It probably happens the first time 2 EntityManager objects on different threads try to run the query at the same time.

EntityManager is being used on a single thread. I can't easily reproduce this, except in a specific integration test while playing with setOrdinalParametersZeroBased. It happened in Confluence while deleting a space for a user one time after running in production for all instances in Confluence Cloud for 9 hours.

Positional parameter [0] not set
at org.hibernate.query.internal.QueryParameterBindingsImpl.verifyParametersBound(QueryParameterBindingsImpl.java:255)
at org.hibernate.query.internal.AbstractProducedQuery.beforeQuery(AbstractProducedQuery.java:1307)
at org.hibernate.query.internal.NativeQueryImpl.beforeQuery(NativeQueryImpl.java:222)
at org.hibernate.query.internal.AbstractProducedQuery.list(AbstractProducedQuery.java:1396)

Environment

Linux, multi-core processor

Status

Assignee

Andrea Boriero

Reporter

ClintonV

Fix versions

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Affects versions

5.2.2

Priority

Major