Hi,
I have the following simple data model. TableA's relationship to children is 1 to many. The child table has a FK that points back to the PK of TableA, a standard 1:n relationship.
I have an HQL query in the form of
from TableA a left join fetch a.children ch where a.attributeA = '<something>' and ch.attributeB = 'ABC'
The problem is that hibernate will only populate the set of children of the TableA object with only children that match attributeB = 'ABC'. Whereas I would like to have in the results - if TableA has a child that match the criteria (along with the other TableA criteria) then bring back the TableA row along with *all* the children, not just the ones meeting attributeB = 'ABC'.
Is that possible in HQL? It's not really an outer join.
I know it's possible doing it via 2-pass, but trying to avoid it.
select distinct (a.primaryKey) from TableA a left join fetch a.children ch where a.attributeA = ... and ch.attributeB = 'ABC'
and then from TableA where primaryKey in (....)
seems like a kludgy way of doing it.
Thanks in advance, Giao Nguyen
|