Renee,
check JPA specification chapter 4.4.4 "Path Expressions". It says: "Path
expression navigability is composed using “inner join” semantics. That
is, if the value of a non-terminal association-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.".
So if you want to solve your issue, you have to explicitely use left
outer join declaration (see JPA specification chapter 4.4.5.2 "Left
Outer Joins"):
SELECT w FROM MyObj w LEFT JOIN w.elem3 x WHERE (w.elem1.itemID =
:elemid) OR (w.elem2.itemID = :elemid) OR ((w.elem3 IS NOT NULL) AND
(w.elem3.itemID = :elemid))
HTH
Markus
glassfish_at_javadesktop.org schrieb:
> Hi,
>
> I have an object that has up to three elements in it. It always has the first two, but the third element is optional. If I use a query such as:
>
> @NamedQuery(name = "findObjsByElemID", query = "SELECT w FROM MyObj w WHERE (w.elem1.itemID = :elemid) OR (w.elem2.itemID = :elemid)")
>
> it will correctly return objects that have either two or three elements and match the first or second element. If, however, I add a check for the optional third element as in:
>
> @NamedQuery(name = "findObjsByElemID", query = "SELECT w FROM MyObj w WHERE (w.elem1.itemID = :elemid) OR (w.elem2.itemID = :elemid) OR ((w.elem3 IS NOT NULL) AND (w.elem3.itemID = :elemid))")
>
> it no longer returns objects that have only two elements defined. It will correctly find any objects that have three elements and match, but it does not return objects with only two elements.
>
> Any ideas what I might be doing wrong?
>
> Thanks for any help,
>
> Renee
> [Message sent by forum member 'drrevis' (drrevis)]
>
> http://forums.java.net/jive/thread.jspa?messageID=286191
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
>
--
http://www.xing.com/go/invita/58469