I see 2 problems here:
- The coalesce(:departments) works fine, with departments either being null or containing 1 or even 500 elements. With this issue I just want it to behave consistently for an empty list.
- Removing the coalesce part while using the empty list param leads to the SQL
select u1_0.id,u1_0.id_department,u1_0.namefrom userr u1_0
where 1=0
and 0 results. That’s not what I intended. I understand that a predicate u.department in () is mathematically false at any time (1=0). That's why I’m bypassing it's evaluation when the list is empty. A workaround/solution may be to keep the coalesce and pass null instead of an empty list. But in Java it's a good practice to use empty lists instead of null 🙂 . |