In paragraph 4.9 of persistence spec. it is said that:
When the ORDER BY clause is used in a query, each element of the SELECT clause of the query must be one of the following: 1. an identification variable x, optionally denoted as OBJECT(x) 2. a single_valued_association_path_expression 3. a state_field_path_expression In the first two cases, each orderby_item must be an orderable state-field of the entity abstract schema type value returned by the SELECT clause. In the third case,the orderby_item must evaluate to the same state-field of the same entity abstract schema type as the state_field_path_expression in the SELECT clause.
In "Pro EJB 3 Java Persistence API" (chapter 7) there is an example of, in my opinion, incorrect query:
SELECT e FROM Employee e JOIN e.department d ORDER BY d.name, e.name DESC
because, d.name isn't listed in select clause.
But this query works perfect on Toplink Essentials. Am I misunderstanding the spec or is it a bug/feature of Toplink Essentials?