users@glassfish.java.net

subquery: select sum(x.fieldA + x.fieldB).... help!

From: Witold Szczerba <pljosh.mail_at_gmail.com>
Date: Wed, 4 Apr 2007 17:08:34 +0200

Hello there,
I have to select from database entities, but there is no way of doing
that without adding like this:
 SUM(x.fieldA - x.fieldB)
or like this:
 SUM(x.fieldA) - SUM(x.fieldB)

This select is a subquery. Without this simple operation, I will have
to execute a query for every entity (it can be even 50000 entities).
Is there any workaround for this? Do you have any ideas?

p.s.
I saw such an example of hibernate:

select cat.weight + sum(kitten.weight)
from Cat cat
   join cat.kittens kitten
group by cat.id, cat.weight

Is that illegal in TopLink's JPA?