Hi
I have two classes:
Customer and
Survey.
Customer has many-to-one relation to
Survey, and
Survey has one-to-many (ISet) relation to
Customer.
Survey has an integer field
theYear,
Customer has a string field
Name.
I need a following result with one query:
Customer.Name, Count(
Customer.
Surveys) for a particular
theYear value.
The following query
Code:
select c.Name,count(*) from Customer left join c.Surveys s where s.theYear=2005 or s.theYear is null
gives me partial result - customers with some surveys in a year (and the number of surveys in that year) and customers with no surveys at all (number=0). There are no customers only with surveys with
theYear<>2005.
I know where is the problem ( simmilar SQL query gives the exact result ), but I have no idea how to modify the query to get full list of customers. In SQL i would do sth like this:
Code:
select c.Name,(select count(*) from Survey s where s.CustomerId=c.Id and s.theYear=2005) from Customer c
but it is not possible in HQL. Can anybody help?