According to the Java EE 6 docs JPA 1.0 @OrderBy
uses field names vs. JPA 2.0 @OrderColumn
uses column names when declaring the annotations. See here:
http://docs.oracle.com/javaee/6/api/javax/persistence/OrderBy.html
http://docs.oracle.com/javaee/6/api/javax/persistence/OrderColumn.html
The former is available since JPA 1.0, the latter was added with JPA 2.0. If you read the docs for a moment it becomes clear that @OrderBy
uses fields/properties to specify the order, whereas @OrderColumn
takes an SQL/DDL column name.
Why has it been made that way? To me this looks plain inconsistent.
Is there a deeper point why things have been made that way? Is it a JPA 1.0 relic?
Try to understand the difference between an ordered list (JPA1, JPA2), and an indexed list (JPA2). One orders the elements by a condition, and the other preserves the position they were inserted at. They fulfil different use-cases. OrderColumn allows specification of a column name for schema generation purposes. OrderBy provides a query mechanism for retrieval purposes. Consequently what the annotations and XML allow input of are different.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With