Hi, I am new to Hibernate and puzzling over a many-to-one association mapping and the resulting sql output:
I have the following mappings:
Code:
<hibernate-mapping>
<class name="StaffSolution" table="BK9_T_DRP_STAFF_SOLUTION">
<!-- other properties and associations -->
<many-to-one class="Building" column="CURRENT_BU_BLD_FK" fetch="join" lazy="false" name="currentBuilding"/>
<many-to-one class="Employee" column="SOLUTION_OWNER_EMP_ID" fetch="join" name="solutionOwner" />
<many-to-one class="Employee" column="SOLUTION_MAINTAIN_EMP_ID" fetch="join" name="solutionMaintainer" />
</class>
</hibernate-mapping>
<hibernate-mapping>
<class name="Employee" table="BK9_T_EMPLOYEE">
<!-- other properties and associations -->
<many-to-one class="OrganisationUnit" column="OU_PK" fetch="join" name="organisationUnit" update="false" />
<many-to-one class="Building" column="BUILDING_PK_1" fetch="join" lazy="false" name="building" update="false" />
</class>
</hibernate-mapping>
and the resulting sql output:
Quote:
[6/22/09 9:39:19:593 SGT] 0000002d SystemOut O Hibernate:
select ****
from
BK9_T_DRP_STAFF_SOLUTION staffsolut0_
left outer join
BK9_T_BUILDING building1_
on staffsolut0_.CURRENT_BU_BLD_FK=building1_.BUILDING_PK
left outer join
BK9_T_EMPLOYEE employee2_
on staffsolut0_.SOLUTION_OWNER_EMP_ID=employee2_.GPN
left outer join
BK9_T_OU organisati3_
on employee2_.OU_PK=organisati3_.OU_PK
left outer join
BK9_T_BUILDING building4_
on employee2_.BUILDING_PK_1=building4_.BUILDING_PK
left outer join
BK9_T_EMPLOYEE employee5_
on staffsolut0_.SOLUTION_MAINTAIN_EMP_ID=employee5_.GPN
where
staffsolut0_.PLAN_ID=?
What I don't understand is the difference of the sql joining the two BK9_T_EMPLOYEE (highlighted in
blue and
red), given the mappings above: why the first BK9_T_EMPLOYEE join with BK9_T_OU and BK9_T_BUILDING but the second BK9_T_EMPLOYEE does not? Can anyone help me explain that? Thank you.
Regards,
Rujing