Community
Participate
Working Groups
Build Identifier: 2.3.0.v20110604-r9504 Given following entities: @Entity public class TestEntity { @ManyToOne private RelatedEntity relation; } @Entity public class RelatedEntity { private String name; } Query q = em.createQuery("SELECT te FROM TestEntity te ORDER BY te.relation.name"); q.getResultList(); Result contains only those TestEntities having non-null relation field. Looking at the generated SQL the reason seems to be that EclipseLink does select from multiple tables instead of left join (i.e. SELECT FROM Table1, Table2 instead of SELECT FROM Table1 LEFT JOIN Table2). Somewhat related but different issue: http://bugs.eclipse.org/bugs/show_bug.cgi?id=294092. Reproducible: Always Steps to Reproduce: 1. Run the attached testcase 2. 3.
Created attachment 207018 [details] Test case. Just run mvn clean install and observe the test failure.
What happens if you run this query? SELECT te FROM TestEntity te left join te.relation r ORDER BY r.name
Thanks, that works fine. However, in our case the queries are programmatically generated so unfortunately it's not very straightforward workaround.
The only reference to this in the JPA specification that I can find is from section 4.4.4 - Patch Expressions: "Path expression navigability is composed using “inner join” semantics. That is, if the value of a non-terminal field in the path expression is null, the path is considered to have no value, and does not participate in the determination of the result." I couild not find anything that indicated this should behave any differently in an ORDER BY clasue. Based on the above, I am closing this bug. I can't see a away to change this behavior without specifically disobeying the spec.
In my interpretation 4.4 is talking about WHERE clause. In 4.9: "The ORDER BY clause allows the objects or values that are returned by the query to be ordered." It doesn't hint at all that ORDER BY would be allowed to affect the result of the query.
The part of the spec that I think relates is this: "the path is considered to have no value" To me, something with no value cannot participate in the ORDER BY
Tom, you are correct. The spec lead kindly confirmed that it is an invalid query (disallowed by the first order_by requirement in 4.9). I'll reopen and update the subject. Instead of executing the query and returning undefined result EclipseLink should not allow an the query to be executed.
Reclosing based on feedback from JPA spec comittee confirming what I have said above.
Sorry, didn't read what you had done. Reopening.
The Eclipselink project has moved to Github: https://github.com/eclipse-ee4j/eclipselink