I have a Entity :
class User{
Long id;
String group_name;
User head;
}
I have to get ordered users in order : order by group_name, if user is head then first (head means than head.id = id).
I make HQL Query : select u from User u order by u.group_name, case when u = head then 0 else 1;
But it's not working;
In result I would like to have : (group_name : user)
- g1 John (head)
- g1 James
- g1 Adam
- g2 Brian (head)
- g2 Martin
How to make correct HQL query ?