JPA 2.0 subselect / subquery in order by clause with criteria api

て烟熏妆下的殇ゞ 提交于 2019-12-06 05:51:47

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!