users@glassfish.java.net

Re: JPA Query WHERE syntax

From: Markus KARG <markus.karg_at_gmx.net>
Date: Sun, 13 Jul 2008 12:29:57 +0200

Michael,

thank you for correcting me. You are right, there was a typo in my proposal.

Didn't actually know that one can compare instances directly in QL.
Pretty cool!

Have Fun
Markus

glassfish_at_javadesktop.org schrieb:
> 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
>
> ---------------------------------------------------------------------
> 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