setParameter doesn't work in native Query if Query is already executed with different parameter value for collection type when new collection length is less than the previous

Description

setParameter doesn't work if Query is already executed with different parameter value for collection type when new collection length is less than the old.

Caused by: org.hibernate.QueryException: Named parameter does not appear in Query: ids_2 [update student set status=?, modification_time = CURRENT_TIMESTAMP where id in (?, ?)]
at org.hibernate.engine.query.spi.NativeSQLQueryPlan.getNamedParameterLocs(NativeSQLQueryPlan.java:65)
at org.hibernate.engine.query.spi.NativeSQLQueryPlan.bindNamedParameters(NativeSQLQueryPlan.java:134)
at org.hibernate.engine.query.spi.NativeSQLQueryPlan.performExecuteUpdate(NativeSQLQueryPlan.java:200)
at org.hibernate.internal.SessionImpl.executeNativeUpdate(SessionImpl.java:1575)
at org.hibernate.query.internal.NativeQueryImpl.doExecuteUpdate(NativeQueryImpl.java:274)
at org.hibernate.query.internal.AbstractProducedQuery.executeUpdate(AbstractProducedQuery.java:1504)
... 29 more

Environment

None

Activity

Show:
Rabin Banerjee
March 14, 2019, 10:13 AM

This is happened because when first time the query is executed the native query is expanded from

update student set status=:status, modification_time = CURRENT_TIMESTAMP where id in (:ids)

To,

update student set status=:status, modification_time = CURRENT_TIMESTAMP where id in (:ids_0,:ids_1,:ids_2)

On executing next parameter set its still expecting the ids_2 even though there are only two values.

Rabin Banerjee
March 14, 2019, 10:35 AM
Rabin Banerjee
March 14, 2019, 11:12 AM

The problem is when re using a native query with a Collection type param , its not removing the already expanded parameter from parameterBindingMap in expandListValuedParameters. For example first time the Collection had 3 values so it expanded to ids_0 , ids_1, ids_2 . Then next run it has two values so its just updating ids_0 , ids_1 not removing ids_2 from parameterBindingMap which is causing Caused by: org.hibernate.QueryException: Named parameter does not appear in Query: ids_2

Assignee

Rabin Banerjee

Reporter

Rabin Banerjee

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

backportDecision

None

Affects versions

Priority

Critical
Configure