Hi all,
Wondering if someone can help. I have three classes:
ClassA,
ClassB, and
ClassC.
ClassB has two one-to-many relationships: one with
ClassA and one with
ClassC. I'm trying to execute HQL that resembles the following:
Code:
select new ClassA( c.objectB, avg(c.someValue) )
from ClassC as c
group by ( c.objectB )
In the query,
objectB is of type
ClassB.
Now,
ClassA has a constructor defined as:
ClassA(ClassB, double), which I'm trying to call with this query. Unfortunately, it fails with a SQL exception because the generated SQL SELECT contains all of the properties of
ClassB, but the GROUP BY contains only the ID of
ClassB.
My question is: How can I get this query to work? If I change the SELECT clause to select only the ID of
objectB, then it still doesn't work because the constructor would need to take the ID as input rather than the entity object itself. (I want the object itself or at least a proxy.)
I'm using Hibernate 2.1.6. Any ideas?
Thanks.