Cannot use lists and Enums in where clause

Description

This is a sample project demonstrating several Hibernate 6 problems related to using 'IN (:list)' and Enums (for example select i from ItemEntity where i.status = :status) in where clause: https://github.com/svkap/hibernate-6-bug-sample

The project uses docker-compose for spinning up PostgreSQL + Flyway for db initialization. It uses spring-data and lombok.

It seems there are problems when lists are used in queries and with coalesce.

The Entities are fairly simple but have different column types.
There are 3 different entity definition:
1. Using PostgreSQL enum + @Enumerated(EnumType.STRING)
2. Using varchar column + @Convert(...)
3. Using int column + @Convert(...)

The sample project tests several different queries and scenarios.
Result summary:

1. Entity creation work for all scenarios.
2. Entity update work for all scenarios.
3. Return entity, use SpEl ( (:#{#list == null} = true) OR (i.list IN (:list)) ) works in JPQL
4. Pass Integer/String to native query works for coalesce and SpEl only when projection is returned


The exceptions seem the same when using PostgreSQL enum, Converter + String and Converter + Integer:

1. Return entity, native query + pass enums to repository method + ( (coalesce(:list, null) is null) OR (i.list IN (:list)) )
java.lang.NullPointerException: Cannot invoke "org.hibernate.metamodel.mapping.JdbcMapping.getJdbcValueBinder()" because "jdbcMapping" is null
2. Return entity, native query + pass strings to repository method + ( (coalesce(:list, null) is null) OR (i.list IN (:list)) )
org.springframework.dao.InvalidDataAccessResourceUsageException: Unable to find column position by name: id; SQL [n/a]
3. Return entity, native query + pass null to repository method + ( (coalesce(:list, null) is null) OR (i.list IN (:list)) )
org.springframework.dao.InvalidDataAccessResourceUsageException: Unable to find column position by name: id; SQL [n/a]
4. Return entity, native query + pass enums to repository method + ( (:#{#list == null} = true) OR (i.list IN (:list)) )
java.lang.NullPointerException: Cannot invoke "org.hibernate.metamodel.mapping.JdbcMapping.getJdbcValueBinder()" because "jdbcMapping" is null
5. Return entity, native query + pass null to repository method + ( (:#{#list == null} = true) OR (i.list IN (:list)) )
org.springframework.dao.InvalidDataAccessResourceUsageException: Unable to find column position by name: id; SQL [n/a]
6. Return entity, native query + pass enum to repository method
java.lang.NullPointerException: Cannot invoke "org.hibernate.metamodel.mapping.JdbcMapping.getJdbcValueBinder()" because "jdbcMapping" is null
7. Return entity, native query + pass string to repository method + ( (:#{#list == null} = true) OR (i.list IN (:list)) )
org.springframework.dao.InvalidDataAccessResourceUsageException: Unable to find column position by name: id; SQL [n/a]
8. Return entity, JPQL query + pass enum to repository method + ( (coalesce(:list, null) is null) OR (i.list IN (:list)) )
java.lang.ClassCastException: class java.util.ImmutableCollections$List12 cannot be cast to class java.lang.Enum (java.util.ImmutableCollections$List12 and java.lang.Enum are in module java.base of loader 'bootstrap')
9. Return projection, native query + pass enum to repository method + ( (:#{#list == null} = true) OR (i.list IN (:list)) )
java.lang.NullPointerException: Cannot invoke "org.hibernate.metamodel.mapping.JdbcMapping.getJdbcValueBinder()" because "jdbcMapping" is null

Activity

Show:

German Chyzhov April 18, 2023 at 1:31 PM

Same problem, that Enums does not work with Postgres in 6.1.7, I need to cast enums to strings every time I perform a query

Details

Assignee

Reporter

Worked in

Components

Affects versions

Priority

Created February 28, 2023 at 11:34 AM
Updated July 25, 2023 at 12:32 PM