After upgrading hibernate from v5 to v6, there are type issues with some queries

We are upgrading our Spring Boot app from 2.7.18 to 3.0.0 (and thus upgrading hibernate-core from 5.6.15.Final to 6.1.5.Final).
This was working fine with hibernate 5, but after upgrading to 6 it starts randomly failing:

@Query("""
            select new com.eryce.taskservice.dto.TaskWithContext(t, tb)
            from Task t
            inner join TaskBoard tb on (t.archived = false and tb.id = t.taskBoardId)
            where ( t.taskBoardId in :taskBoardIdsWithManagePermission or t.assigneeId = :loggedUserId )
                and ( (:assigneeIds) is null or t.assigneeId in :assigneeIds or ( t.assigneeId is null and -1 in :assigneeIds ) )
                and ( (:statuses) is null or t.status in :statuses )
                and ( (:priorities) is null or t.priority in :priorities )
                and ( (:creatorIds) is null or t.createdById in :creatorIds )
                and ( (:organizationIds) is null or tb.organizationAccountId in :organizationIds )
                and ( (:taskBoardIds) is null or tb.id in :taskBoardIds )
                and ( :deadline is null or (:deadline = 'ACTIVE' and (t.dueDate is null or t.dueDate >= CURRENT_TIMESTAMP)) or (:deadline = 'EXPIRED' and t.status <> 'DONE' and t.dueDate < CURRENT_TIMESTAMP) )
                and ( (:taskIds) is null or t.id in :taskIds )
            """)
    Slice<TaskWithContext> filterUnarchivedTasks(Collection<Long> assigneeIds, String deadline, Collection<TaskStatus> statuses, Collection<TaskPriority> priorities, Collection<Long> creatorIds,
                                                 Collection<Long> organizationIds, Collection<String> taskBoardIds, Collection<String> taskBoardIdsWithManagePermission, Collection<String> taskIds, long loggedUserId, Pageable pageable);

The errors I’m getting (randomly) are:

  1. java.lang.IllegalArgumentException: Parameter value [[-1]] did not match expected type [basicType@14(java.lang.Integer,4) ]
  2. java.lang.IllegalArgumentException: Parameter value [[1]] did not match expected type [BasicSqmPathSource(organizationAccountId : Long) ]
  3. java.lang.ClassCastException: class java.util.HashSet cannot be cast to class java.lang.Enum (java.util.HashSet and java.lang.Enum are in module java.base of loader 'bootstrap')
  4. java.lang.AssertionError

And sometimes it just executes fine.

Please note that the same error is thrown whether it is examining if literal is in the collection
(-1 in :assigneeIds)
or if checking if entity’s property is in the collection
(tb.organizationAccountId in :organizationIds)

Just to mention, if I add coalesce into the query and kinda format this -1 parameter, it executes fine all the time:

@Query("""
            select new com.eryce.taskservice.dto.TaskWithContext(t, tb)
            from Task t
            inner join TaskBoard tb on (t.archived = false and tb.id = t.taskBoardId)
            where ( t.taskBoardId in :taskBoardIdsWithManagePermission or t.assigneeId = :loggedUserId )
                and ( coalesce(:assigneeIds) is null or t.assigneeId in :assigneeIds or ( t.assigneeId is null and (-1L) in :assigneeIds ) )
                and ( coalesce(:statuses) is null or t.status in :statuses )
                and ( coalesce(:priorities) is null or t.priority in :priorities )
                and ( coalesce(:creatorIds) is null or t.createdById in :creatorIds )
                and ( coalesce(:organizationIds) is null or tb.organizationAccountId in :organizationIds )
                and ( coalesce(:taskBoardIds) is null or tb.id in :taskBoardIds )
                and ( :deadline is null or (:deadline = 'ACTIVE' and (t.dueDate is null or t.dueDate >= CURRENT_TIMESTAMP)) or (:deadline = 'EXPIRED' and t.status <> 'DONE' and t.dueDate < CURRENT_TIMESTAMP) )
                and ( coalesce(:taskIds) is null or t.id in :taskIds )
            """)
    Slice<TaskWithContext> filterUnarchivedTasks(Collection<Long> assigneeIds, String deadline, Collection<TaskStatus> statuses, Collection<TaskPriority> priorities, Collection<Long> creatorIds,
                                                 Collection<Long> organizationIds, Collection<String> taskBoardIds, Collection<String> taskBoardIdsWithManagePermission, Collection<String> taskIds, long loggedUserId, Pageable pageable);

But this does not make much sense to me. DB underneath is PostgreSQL.

Hibernate ORM 6.1 is not supported anymore. Please upgrade to the latest version i.e. 6.5.2.Final

Thanks for the quick answer.
Can I upgrade to something below 6.5.1? I see that Spring Boot 3.3.0 incorporates Hibernate 6.5.1, but we are trying to upgrade to Spring Boot 3.0.0 first, and I guess that’s too much of version difference to put Hibernate 6.5.1 under Spring Boot 3.0.0

AFAIK, Spring Boot usually requires the same major/minor version family i.e. you can update bug-fix versions, but not major or minor versions of Hibernate ORM.

What’s the lowest Hibernate ORM version that is still supported? (just trying to minimize Spring Boot and overall upgrade)

It’s always the latest version that receives community support. Right now, that is 6.5, but in June when we release 6.6, support for 6.5 will end.
You can read more about this on our maintenance policy page. If you need better support, you will have to become a Red Hat customer. Then you can create support tickets also for limited support versions which are 6.2 and 6.4.

All clear, thanks for the response. Queries work fine with Hibernate 6.5.

What confused me, is that Hibernate 6.4 is at end-of-life, while Hibernate 6.2 is at limited-support.

Anyway, continuing with Hibernate 6.5 and Spring Boot 3.3.0 (which came out just a couple of days ago!).
Thanks for the help!

I just updated the status of ORM 6.4 since it actually receives limited support.

1 Like