I'm using Hibernate 4.3.1 final, Mysql 5.5 and I want to use an "order by case" order logic on some joined entities.
A pure sql representation of what I wish to achieve would look something like:
select adv.id, adv.published_date
from advert as adv
join account as act on act.id = adv.act_id
join account_status as aas on aas.id = act.current_aas_id
order by case aas.status
when 'pending' THEN 1
when 'approved' THEN 1
else 2
end, adv.published_date;
This orders the adverts of pending and approved accounts before those of deactive accounts.
I've managed to do all the select query using hibernate criteria, but I'm not sure how to specify the order by case statement using that api.
I found this post:
but I need to reference joined entity classes in the order by case and I'm not sure how to do that.
Any help or suggestions much appreciated.