two domain classes (beans)
A and B, A has a property b of type B (-> A.b) In addition, A is the parent of an inheritance hierarchy using a single table.
I would like to join these using HQL and to preserve all Bs that are not associated with an A in the result set. If there are associations between A and B, I want only some of them based on some criteria on A.
My initial query looked like this
SELECT (a.something, b.something)
FROM A as a RIGHT OUTER JOIN a.b
WHERE a.dateCreated < someDate;
The problem with this query: a is sometimes null such that the WHERE criteria resolves to false and the tuple is not returned so that the result set does not contain Bs that are not associated to an A.
So I modified the query to something like this:
SELECT (a.something, b.something)
FROM A as a RIGHT OUTER JOIN a.b
WHERE a is null or (a.dateCreated < someDate);
This does not help as in the generated SQL, it does not seem possible to control where the class selection statement, e.g.
where a.class in ('someChildOfA', 'anotherChildOfA', 'aThirdChildOfA')
is inserted; it would have to go inside the parentheses, i.e.
where a is null or (a.dateCreated < someDate and a.class in ('someChildOfA', 'anotherChildOfA', aThirdChildOfA'))
but it ends up being added outside, i.e.
where (a.id is null OR dateCreated < someDate) and a.class in ('someChildOfA', 'anotherChildOfA', 'aThirdChildOfA')
Right now, I am a bit out of ideas... Any (maybe even cleaner) suggestions? If it matters, I am using Grails.
Thanks