users@glassfish.java.net

JPA Query WHERE syntax

From: <glassfish_at_javadesktop.org>
Date: Sat, 12 Jul 2008 14:30:59 PDT

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