Hi all,
I'm in process of migrating an old "classic ASP" application to J2EE/Hibernate. I have a problem with the following type of SQL statements:
SELECT parent.id, parent.name, parent.column1, count(child.id) AS no_of_children
FROM parent
INNER JOIN child ON child.parent_id = parent.id
GROUP BY parent.id, parent.name, parent.column1
How do I express something like this in HQL? I tried to map the children as a collection (by using many-to-one) and get the number of children from the collection size, but then Hibernate has to load all "child" entities, for each parent separately.
This results in executing around 1000 DB queries instead of 1, with all resulting performance problems.
Is there any way around this?