Hello everybody,
I have the following problem:
There is a parent class (let's name it "PARENT") which has a one-to-many relationship to a child class (let's name such a class as "CHILD"). So, a PARENT instance contains a Collection with CHILDs (let's name the collection class property as "childs").
Such a collection is specified in the Hibermnate-config file for PARENT like the following:
Code:
<bag name="childs" inverse="true" cascade="none" access="field"
where="<<HUGE CONDITION>>" >
<key column="SOURCE_ID" />
<one-to-many class="CHILD" />
</bag>
A PARENT may have no CHILDs such that there is no corresponding rows in the CHILD-related DB table at all or there are some rows, but they are not considrered because of 'WHERE' in the mapping.
I need to produce an HQL query which will return in each result "row" some details about a PARENT along with details of a corresponding CHILD (if any). Logically, a LEFT JOIN is a solution. Something like:
Code:
select p.key, ch.key
from PARENT p
left join p.childs as ch
But the 'WHERE' in the mapping prevents such a LEFT JOIN: if no CHILDs exists for a PARENT (taking the 'WHERE' into consideration), then nothing is returned (not just 'NULL' in place of 'ch.key'). I know such a "WHERE-influenced" logic for HQL joins, so it looks like not an extraordinary thing.
But I would need to write a query which delivers NULLs in place of CHILDs data if it does not exist. The WHERE condition can not be eliminated from mapping. Are there any ways to get what I want?
Thanks in advance,
Andrew