JPA @OrderBy() Through Relational Table

前端 未结 1 2019
故里飘歌
故里飘歌 2021-01-23 19:27

I need some help with the JPA Framework. I\'ve read some answers \"kind of\" about this topic but I couldn\'t reach any conclusion.

First heres an examplo of the design

1条回答
  •  臣服心动
    2021-01-23 20:01

    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/

    0 讨论(0)
提交回复
热议问题