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:
java.lang.IllegalArgumentException: Parameter value [[-1]] did not match expected type [basicType@14(java.lang.Integer,4) ]
java.lang.IllegalArgumentException: Parameter value [[1]] did not match expected type [BasicSqmPathSource(organizationAccountId : Long) ]
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')
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.