users@glassfish.java.net

wrong JPAQL->SQL translation in GF2 RC4

From: Witold Szczerba <pljosh.mail_at_gmail.com>
Date: Tue, 28 Aug 2007 14:09:11 +0200

Hi there,
I have a query in JPAQL that is still incorrectly translated into SQL
(Oracle) by GF2 RC4.
I noticed similar behavior about 6 months ago in GF1 (and I filled an
issue), but it is still not fixed :/ For some time I did not have time
to follow that issue, but today I saw "RC4 is going to be final soon".
I downloaded it, checked some simple query and it is broken :(

Now, I am really worried this bug might stay in final release and it
will not be fixed anytime soon. Can someone, please, take a look at
TopLink internals to see what is happening?

Here is an example JPA Query:
SELECT b.id, COUNT(e1), COUNT(e2)
  FROM BankStatement b
   LEFT JOIN b.entries e1
   LEFT JOIN b.entries e2
  WHERE e2.transactionAssigned IS NULL
  GROUP BY b.id

And this is what TopLink Essentials does: (SQL, Oracle flavor)
SELECT t0.ID, COUNT(t1.ID), COUNT(t1.ID) FROM BANKSTATEMENT t0,
BANKSTATEMENTENTRY t1 WHERE ((t1.TRANSACTIONASSIGNED_ID IS NULL) AND
(t1.BANKSTATEMENT_ID (+) = t0.ID)) GROUP BY t0.ID

As you can see it ignores "e1" and "e2", treats them as one, like "e2"
had never existed.
This bug is really painful bug, many, many queries in my application
have to look awful because of this bug... is there any shadow of hope
it might be fixed in GF v2 final?

Regards,
Witold Szczerba

P.S.
Note, this is not a special case, TopLink acts like that in every
query, where more than one alias is assigned to any relation.