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

**URL:** <https://discourse.hibernate.org/t/after-upgrading-hibernate-from-v5-to-v6-there-are-type-issues-with-some-queries/9606>\
**Category:** Hibernate ORM\
**Created:** [May 27, 2024, 11:40am UTC](https://discourse.hibernate.org/t/after-upgrading-hibernate-from-v5-to-v6-there-are-type-issues-with-some-queries/9606 "2024-05-27T11:40:32Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![vedranmimic](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/vedranmimic/32/3232_2.png) [@vedranmimic](https://discourse.hibernate.org/u/vedranmimic)\
**Post date:** [May 27, 2024, 11:40am UTC](https://discourse.hibernate.org/t/after-upgrading-hibernate-from-v5-to-v6-there-are-type-issues-with-some-queries/9606/1 "2024-05-27T11:40:32Z")

</div>

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:

```auto
@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:

```auto
@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.

---

<div class="post-metadata">

**Author:** ![beikov](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/beikov/32/258_2.png) [@beikov](https://discourse.hibernate.org/u/beikov)\
**Post date:** [May 27, 2024, 11:46am UTC](https://discourse.hibernate.org/t/after-upgrading-hibernate-from-v5-to-v6-there-are-type-issues-with-some-queries/9606/2 "2024-05-27T11:46:21Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![vedranmimic](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/vedranmimic/32/3232_2.png) [@vedranmimic](https://discourse.hibernate.org/u/vedranmimic)\
**Post date:** [May 27, 2024, 12:12pm UTC](https://discourse.hibernate.org/t/after-upgrading-hibernate-from-v5-to-v6-there-are-type-issues-with-some-queries/9606/3 "2024-05-27T12:12:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![beikov](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/beikov/32/258_2.png) [@beikov](https://discourse.hibernate.org/u/beikov)\
**Post date:** [May 27, 2024, 12:18pm UTC](https://discourse.hibernate.org/t/after-upgrading-hibernate-from-v5-to-v6-there-are-type-issues-with-some-queries/9606/4 "2024-05-27T12:18:42Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![vedranmimic](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/vedranmimic/32/3232_2.png) [@vedranmimic](https://discourse.hibernate.org/u/vedranmimic)\
**Post date:** [May 27, 2024, 12:21pm UTC](https://discourse.hibernate.org/t/after-upgrading-hibernate-from-v5-to-v6-there-are-type-issues-with-some-queries/9606/5 "2024-05-27T12:21:51Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![beikov](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/beikov/32/258_2.png) [@beikov](https://discourse.hibernate.org/u/beikov)\
**Post date:** [May 28, 2024, 8:11am UTC](https://discourse.hibernate.org/t/after-upgrading-hibernate-from-v5-to-v6-there-are-type-issues-with-some-queries/9606/6 "2024-05-28T08:11:20Z")

</div>

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](https://hibernate.org/community/maintenance-policy/) page. If you need better support, you will have to become a [Red Hat customer](https://hibernate.org/orm/support/). Then you can create support tickets also for limited support versions which are 6.2 and 6.4.

---

<div class="post-metadata">

**Author:** ![vedranmimic](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/vedranmimic/32/3232_2.png) [@vedranmimic](https://discourse.hibernate.org/u/vedranmimic)\
**Post date:** [May 28, 2024, 8:47am UTC](https://discourse.hibernate.org/t/after-upgrading-hibernate-from-v5-to-v6-there-are-type-issues-with-some-queries/9606/7 "2024-05-28T08:47:55Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![beikov](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/beikov/32/258_2.png) [@beikov](https://discourse.hibernate.org/u/beikov)\
**Post date:** [May 28, 2024, 1:27pm UTC](https://discourse.hibernate.org/t/after-upgrading-hibernate-from-v5-to-v6-there-are-type-issues-with-some-queries/9606/8 "2024-05-28T13:27:19Z")

</div>

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