JPA @OrderBy() Through Relational Table

假如想象 提交于 2019-12-02 12:13:48

The API docs for @OrderBy note:

The property or field name must correspond to that of a persistent property or field of the associated class or embedded class within :

http://docs.oracle.com/javaee/6/api/javax/persistence/OrderBy.html

so sorting AB in A by a property of B is not possible.

The alternatives are to write a query or do an in memory sort by some means. Hibernate, for example, has an @Sort annotation which you can use to apply an in-memory sort on load, either by having the target Entity implement Comparable or by specifying a Comparator:

See section 2.4.6.1:

http://docs.jboss.org/hibernate/annotations/3.5/reference/en/html_single/

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