persistence@glassfish.java.net

RE: EJB QL subquery fix

From: Gordon Yorke <gordon.yorke_at_oracle.com>
Date: Fri, 10 Mar 2006 15:23:30 -0500

Hello Michael,
        This looks good.
--Gordon

-----Original Message-----
From: Michael Bouschen [mailto:Michael.Bouschen_at_Sun.COM]
Sent: Friday, March 10, 2006 10:04 AM
To: Gordon Yorke; Andrei Ilitchev
Cc: persistence_at_glassfish.dev.java.net
Subject: EJB QL subquery fix


Hi Gordon, hi Andrei,

attached you find a change that (hopefully) fixes the EJB QL subquery
issue you recently filed (glassfish issue 365). I have the feeling 365
is a duplicate of issue 140:
    https://glassfish.dev.java.net/issues/show_bug.cgi?id=140
    https://glassfish.dev.java.net/issues/show_bug.cgi?id=365

In class ParseTree I changed the handling of the ReportQuery instance
for the subquery:
   SELECT e FROM Employee e WHERE EXISTS
    (SELECT p FROM e.phoneNumbers p WHERE p.type = 'Home'
The old used used class PhoneNumber as the reference class of the
subquery. That's why it took the "inner" ExpressionBuilder which does
not know about the field phoneNumbers which then leads to the
InvalidQueryKeyException.

I changed the code in ParseTree in case the the FROM clause of the
subquery defines an identification variable on a collection relationship
field, such as e.phoneNumbers p in the above example. Now it takes the
reference class of 'e' and its ExpressionBuilder for the subquery. This
might be a recursive process in case 'e' itself is defined in a JOIN
clause, then it takes its reference class until it reaches a range
variable. With this change I can successfully run such an EXISTS query.

Please have a look and let me know what you think.

Regards Michael