I have a self referencing table relationship, as in the Hibernate Cat example, mapped as follows:
Code:
<many-to-one name="mother">
<column name="mother_id" />
</many-to-one>
I have a Named Query which seeks to obtain all the Cats in the table with the name "Mittens" OR whose mother is named "Mittens".
Code:
from Cat as cat
where cat.name = "Mittens" or cat.mother.name = "Mittens"
My problem is that when a Cat's row has no mother_id in it, and is named Mittens, it's not returned. So it looks like Hibernate is doing an
inner join instead of an
outer join.
Can I change something in the mappings or my Named Query in order to get back all the Cats named Mittens even if mother_id is null?
Sorry if this is a simple question - I did look for an answer before posting :-)
--------------------------------------------------------------------------------------
P.S. I have tried adding the
outer-join attribute to my <many-to-one> mapping as follows:
Code:
<many-to-one name="mother" outer-join="true">
<column name="mother_id" />
</many-to-one>
However, cases where mother_id was null were still not included.
--------------------------------------------------------------------------------------
P.P.S. I have also tried the following in my Named Query - to no avail
Code:
from Cat as cat
where cat.name = "Mittens" or cat.mother.name = "Mittens" or cat.mother.name is null