Hi i want to sort in HQL
ORDER BY IF g.groupAdminId=:adminid THEN 1 ELSE 0 END ASC
But it doesn\'t work, i want to have all entities where the
I don't believe it is possible to put named parameters outside a where
clause.
It is possible to order according to expressions:
from User U
order by case
when U.group.name = 'Admin' then 0
when U.group.name = 'Superuser' then 1
else 2
end asc
More on case
in HQL docs :
For your particular problem (having admins before other users) I suggest making two queries and combining the two lists in Java.
There are other ways around this but I do not like any of them: