I want to use JPA 2.0 criteria api to build the order by clause with a subselect. I know that you can do that in plain SQL but can it be mapped with criteria api? Can someone please give a code example?
Example:
Order(name, address) // table1
OrderPriority(address, priority) // table2 priority by address
select o from Order o order by (select p.priority from OrderPriority p where
p.address = o.address)
Criteria API queries are converted to JPQL and apparently subqueries in the
order by
clause are not supported in JPQL.Similar StackOverflow answer can be found here.