Following on from a previous thread, I'm trying to understand the apparent inconsistency in Hibernate's outer-join behaviour between <one-to-one> and <many-to-one> associations.
Take the following mapping:
<class name="Parent" table="PARENT">
........
<!--
<one-to-one name="child" class="Child"/>
<many-to-one name="child" class="Child" column="CHILD_ID"/>
-->
</class>
If I uncomment the <one-to-one>, then run the query:
session.find(from Parent");
then Hibernate will not include Child in an outer join. However, if I use the <many-to-one> approach, then Hibernate will fetch Parent and Child together in a single outer join.
I can override this by using FETCH in the query, of course, but I'm trying to change the default behaviour so that the <one-to-one> is fetched in the same way as the <many-to-one>. Why do they behave differently?
|