| I have entity types Task, Patient, and Site. There is an optional @ManyToOne from Task to Patient, and a @ManyToOne from Patient to Site. I want to query for Task's and restrict to those which either have no patient, or for whom the patient's Site is within a certain set of valid sites. To add this restriction we build a subquery like this:
Here is the SQL that gets generated:
Note that the first outer join in the subquery from Task to Patient is omitted. This changes the logic, because now the patient1_.id is null clause can never be true. As a result, this query fails to match tasks that have no associated patient. |