问题
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)
回答1:
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.
来源:https://stackoverflow.com/questions/19549616/jpa-2-0-subselect-subquery-in-order-by-clause-with-criteria-api