Re-using Query instance for multiple executeUpdate calls

To workaround the limited numbers of SQL parameters that can be passed to databases we are using a set of utility methods to execute a query multiple times with a different set of parameter values. This worked fine in Hibernate 5, but results in an exception using Hibernate 6.

Utility methods:

public static void executeClusteredUpdate(List<?> targets, Query query, String targetsParamName)
	int index = 0;
	while (hasMoreElements(targets, index))
		List<?> subTargets = getNextElements(targets, index);
		index += 500;

		query.setParameter(targetsParamName, subTargets).executeUpdate();

public static boolean hasMoreElements(Collection<?> objects, int index)
	return objects.size() > index;

public static <T> List<T> getNextElements(List<T> objects, int index)
	return objects.subList(index, Math.min(objects.size(), (index + 500)));


@NamedQuery(name = "ExampleEntity.resetNameByIds",
        query= "UPDATE ExampleEntity ee" +
                "  SET = null " +
                "WHERE IN (:ids)")
public class ExampleEntity {
    private Long id;

    private String name;


List<Long> ids = new ArrayList<>();
for (int i = 0; i < 10000; i++)

executeClusteredUpdate(ids, entityManager.createNamedQuery("ExampleEntity.resetNameByIds"), "ids");


Caused by: java.lang.NullPointerException: Cannot invoke "java.util.List.size()" because "jdbcParamBinds" is null
	at org.hibernate@6.4.4.Final//org.hibernate.query.sqm.internal.SqmUtil.createJdbcParameterBindings(
	at org.hibernate@6.4.4.Final//org.hibernate.query.sqm.internal.SimpleUpdateQueryPlan.executeUpdate(
	at org.hibernate@6.4.4.Final//org.hibernate.query.sqm.internal.QuerySqmImpl.doExecuteUpdate(
	at org.hibernate@6.4.4.Final//org.hibernate.query.sqm.internal.QuerySqmImpl.executeUpdate(

When using the Hibernate Test project, a different exception occurs:

	at org.hibernate.query.sqm.internal.SqmUtil.createJdbcParameterBindings(
	at org.hibernate.query.sqm.internal.SimpleUpdateQueryPlan.executeUpdate(
	at org.hibernate.query.sqm.internal.QuerySqmImpl.doExecuteUpdate(
	at org.hibernate.query.sqm.internal.QuerySqmImpl.executeUpdate(

I’m not able to attach the test project ZIP.

Is this a bug or are we doing something that is not allowed? Do you have a different solution for us? Thank you very much in advance!

It’s fixed by HHH-18027 Clear expansions NonSelectQueryPlan.executeUpdate call by beikov · Pull Request #8440 · hibernate/hibernate-orm · GitHub, you should update version to 6.4.9 or 6.5.3.

Thank you very much for the information! You are indeed correct, although 6.5.3 is not released yet.