Possible change in collection parameter handling between Hibernate 6.2.6.Final and 6.2.25.Final

Hi,

I am getting the following exception after upgrading my dependencies:

org.hibernate.QueryException:
Named parameter not bound : types_1

The exception occurs while executing a paginated query. The stack trace goes through:

org.springframework.data.jpa.repository.query.JpaQueryExecution$PagedExecution.count

The relevant versions are:

Working:
Spring Boot 3.1.2
Spring Data JPA 3.1.2
Hibernate 6.2.6.Final

Failing:
Spring Boot 3.1.12
Spring Data JPA 3.1.12
Hibernate 6.2.25.Final

When I revert to the older Spring Boot/Hibernate dependency versions, the issue does not occur.

The query contains an optional collection parameter similar to:

AND (
COALESCE(:types) IS NULL
OR entity.type IN (:types)
)

where types is a Set<String>.

The query works with Hibernate 6.2.6.Final but fails with Hibernate 6.2.25.Final.

I understand that collection parameters are normally used with:

entity.type IN (:types)

I also found discussions indicating that list parameters should not be used with COALESCE() or IS NULL.

My questions are:

  1. Is using a collection-valued parameter with COALESCE() unsupported in Hibernate 6.x?

  2. Were there any relevant changes between Hibernate 6.2.6.Final and 6.2.25.Final regarding collection parameter binding?

  3. Could this behavior be related to the pagination count query?

  4. Could the change in Spring Boot / Spring Data JPA versions also be involved?

  5. What is the recommended way to handle an optional collection parameter in JPQL?

I am trying to determine whether this is caused by a change in Hibernate, Spring Data JPA, or simply an unsupported query pattern that happened to work with the older dependency versions.

Thanks!

It never was supported and only worked coincidentally.

Check the changelogs or commits on GitHub to see for yourself.

Maybe, depends what pagination count query you are using.

I have no idea what Spring does here, so yeah, for all I can say, it can also be a Spring bug.

Have separate queries, one for an empty list and another for a non-empty list. Or use Criteria queries e.g. through Spring Data Specifications.