Hello!
I have a problem with a query of mine. The Situation:
2 Entities, Person and Disease.
Persons have: id, name, set of diseases
Disease have: id, name, duration, and a referenced person.
The Relationship is a 1:n relationship, one person can have multible diseases
What i want to do is the following:
I want (if it's possible in one query) to get the the count of the persons and the total duration of those diseases. Result should read like this "there were 300 people ill and this caused 4902 days of sickness"
the last approach i tried was this:
Code:
Query query1 = session.createQuery("
SELECT count(p),
sum(
SELECT sum(d.duration) FROM p.diseases d
)
FROM Person p
WHERE p.diseases.size > 0");
The Error i get is a unexpected Token near the "sum(SELECT" part of the query.
Hibernate version is 3.2.5
Thanks for your help, i'm stuck here for nearly two hours now with this single query..
greetings from Austria,
Klaus