persistence@glassfish.java.net

JPQL: fix invalid SQL for COUNT on joined variablehip

From: Michael Bouschen <Michael.Bouschen_at_Sun.COM>
Date: Thu, 22 Mar 2007 20:46:23 +0100

Hi Tom,

attached you find my fix for issue 2497 "JPQL: Invalid SQL for COUNT on
joined variable"
(https://glassfish.dev.java.net/issues/show_bug.cgi?id=2497). It changes
the generated SQL for queries such as:
  SELECT c.name, COUNT(o) FROM Customer c LEFT JOIN c.orders o GROUP BY
c.name

My change fixes the issue if the class of the joined variable has a
single PK or if it is not a COUNT(DISTINCT o). It does not cover the
case of a COUNT(DISTINCT o) where the class of the variable o has a
composite PK. I propose I checkin the fix, resolve issue 2497 and file a
new P4 issue for the remaining case from above.

You find the fix and new test cases attached. Please have a look.

Thanks!

Regards Michael