I have 2 tables (entity) a person entity and a vacation entity. One person can have many vacations.
What I’m trying to do is the following query:
Select all the persons period!, but for the persons who have a vacations, I want to fetch all of the persons vacations which have a condition , lest just say startDate is between something.
Just to be clear no matter the constraints on the vacations I still want to get all the persons.this is my current HQL query:
select distinct p
from Person as p
left join fetch p.vacations as v
where v.startDate between '2011-07-01' and '2011-07-30'
The problem with it is that it constraint my persons an returns only the ones who have a vacation that respects the condition….Can someone help please?
I have no problem if someone can tell me this in native SQL
UPDATE Resolved in native SQL thanks to @Quasdunk:
SELECT *
FROM person as p
LEFT JOIN
(SELECT * FROM vacation
WHERE startDate BETWEEN '2011-08-01' AND '2011-08-30') as v ON v.person_id = p.id
My new problem is how to convert it to an HQL query so I can fetch the vacations for each person, and the persons to be distinct (the conditions remain the same).
In native SQL this would be:
untested, but you get the idea 🙂