select h.owner, h.address
from org.datanucleus.test.Person
where this.houses.contains(h)
order by h.id asc

can not be executed (NullPointerException thrown), unless the ordering clause is not specified.

Description

following JDOQL,
select h.owner, h.address
from org.datanucleus.test.Person
where this.houses.contains(h)
order by h.id asc
can not be executed (NullPointerException thrown), unless the ordering clause is not specified.

An ordering clause has to be comparable to a candidate (i.e what you're selecting, a row), and in this case "h" could have multiple values for any candidate (row). Consequently it has problems evaluating. Put another way, what SQL are you expecting out of that?

If wanting components of the House then doing
SELECT owner, address FROM House WHERE owner != null ORDER BY id ASC
would make more sense (to me).

Andy Jefferson added a comment - 25/Apr/13 02:11 PM - edited An ordering clause has to be comparable to a candidate (i.e what you're selecting, a row), and in this case "h" could have multiple values for any candidate (row). Consequently it has problems evaluating. Put another way, what SQL are you expecting out of that?
If wanting components of the House then doing
SELECT owner, address FROM House WHERE owner != null ORDER BY id ASC
would make more sense (to me).

Azuo Lee added a comment - 26/Apr/13 08:40 AM In fact, this is just an extended version of the example mentioned by JDO spec 14.10.17:
select e.name
where name.startsWith('Research')
&& emps.contains((com.xyz.hr.Employee) e)
I just want to order the results returned by that query:
select e.name
where name.startsWith('Research')
&& emps.contains((com.xyz.hr.Employee) e)
order by e.name asc
This makes sense if Department and Employee has 1-n "unidirectional" association, and I want to query the names of all Employees of all "Research" Departments.