Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JPA 1.0 @OrderBy uses field names vs. JPA 2.0 @OrderColumn uses column names

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?

like image 252
Kawu Avatar asked Nov 04 '22 01:11

Kawu


1 Answers

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.

like image 123
DataNucleus Avatar answered Nov 09 '22 12:11

DataNucleus