Hello,
I have a query I have written in SQL that I can't figure out how to translate into HQL properly. I have a main table (PACKAGE) that is left-joined to two tables (IMAGE and EMAIL). The object modelling for this is that a Package object contains a collection of Image objects and a collection of Emal objects.
The goal is to produce a report showing how many activated emails and images are in each package. The count of the number of images is broken down by the dimensions of the images within the package. A row from the returned query, for example, should look as follows:
Code:
PACKAGE_NAME='My Package'
EMAIL_COUNT=3
80X60=1
100X60=0
100X70=5
The sql query I execute is as follows:
Code:
select p.package_id, p.display_name, i.width, i.height,
count(distinct i.image_id), count( distinct e.email_id)
from package p
left outer join (select * from image where is_activated=1) i on b.bundle_id=i.bundle_id
left outer join (select * from email where is_activated=1) e on b.bundle_id=e.bundle_id
group by b.bundle_id, i.width, i.height, b.display_name
The problem is that I can't determine if in HQL it is possible to join on the subqueries. That is, I would like my HQL to be something like "...from Package package left join package.images left join package.email", but wit the additional restriction that the join should only occur for activated items; however, I can't determine the correct syntax, if any, to support this.
I also considered an alternate approach using a WHERE clause, but I can't just look for items where i.is_activated=1 or e.is_activated=1 because that would remove all those Packages which contained no activated images or email from the result entirely.
Any ideas?