JPA 2.0 subselect / subquery in order by clause wi

2019-04-10 04:46发布

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条回答
乱世女痞
2楼-- · 2019-04-10 05:28

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.

查看更多
登录 后发表回答