Hi Renee,
Markus is right, the path expression 'w.elem3.itemID' is composed using an inner join and thus MyObj instances not having an elem3 do not match the WHERE clause.
Markus' proposal using an outer join is correct, there is just a small issue with the WHERE clause. You need to use the declared identification variable 'x' in the WHERE clause, otherwise you still have the inner join because of the path expression:
SELECT w FROM MyObj w LEFT JOIN w.elem3 x
WHERE (w.elem1.itemID = :elemid) OR (w.elem2.itemID = :elemid) OR
((x IS NOT NULL) AND (x.itemID = :elemid))
BTW, you can directly compare entity instances in the query:
SELECT w FROM MyObj w LEFT JOIN w.elem3 x
WHERE (w.elem1 = :elem) OR (w.elem2 = :elem) OR ((x IS NOT NULL) AND (x = :elem))
Regards Michael
[Message sent by forum member 'mb124283' (mb124283)]
http://forums.java.net/jive/thread.jspa?messageID=286230