Hi,
I have a question about the SQL that should be generated for a a JPQL
query using a count aggregate in the SELECT clause that counts a joined
variable, e.g.:
SELECT c.name, COUNT(o) FROM Customer c LEFT JOIN c.orders o GROUP BY
c.name
So what is the right SQL for the JPQL COUNT expression?
I think there are three cases and I need some help for case (3):
(1) The entity class Order has a single primary key. Then the SQL should
be "COUNT(o.PK)" where PK is the primary key column of the order table.
(2) Order has a composite primary key and the COUNT does not use
DISTINCT. Then the SQL can do a COUNT on an arbitrary primary key column.
(3) Order has a composite primary key and the JPQL query does a
COUNT(DISTINCT o)). I have no idea what exactly is the right SQL!
Any idea is appreciated!
Regards Michael