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
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/