Hi,
Given the following Model Objects:
Absence, 2 subclasses: WAAbsence & PIAbsence
Expertise, 2 subclasses: WAExpertise & PIExpertise
a WAAbsence can have max 1 WAExpertise
a PIAbsence can have max 1 PIExpertise
Mapping:
Code:
<class name="Absence" table="ABSENCE" discriminator-value="ABS">
<id name="id" type="long" column="ID" >
<generator class="native">
<param name="sequence">SEQ_ABSENCE</param>
</generator>
</id>
<discriminator column="DISCRIMINATOR" />
<subclass name="WAAbsence" discriminator-value="WA">
<many-to-one name="expertise" column="WA_EXPERTISE_ID" class="WAExpertise"/>
<property name="accidentDate" column="ACCIDENT_DT" type="date" not-null="false" />
</subclass>
<subclass name="PIAbsence" discriminator-value="PI">
<many-to-one name="expertise" column="PI_EXPERTISE_ID" class="PIExpertise"/>
<property name="declarationDate" column="PI_DECL_DT" type="date" not-null="false" />
</subclass>
</class>
Absences are saved in 1 table:
ABSENCE(ID, DISCRIMINATOR, WA_EXPERTISE_ID, PI_EXPERTISE_ID, ACCIDENT_DT, PI_DECL_DT, ...)
Expertises in 2 tables:
WA_EXPERTISE & PI_EXPERTISE
When using searchcriteria to find certain absences, hibernate generates the following code:
Code:
select
this_.ID as y0_,
p2_.FIRST_NAME as y1_,
p2_.LAST_NAME as y2_,
md4_.MEDICAL_NUMBER as y3_,
this_.NUMBER_OF_DAYS as y4_,
this_.START_DT as y5_,
c1_.END_DT as y6_,
this_.DISCRIMINATOR as y7_,
c1_.ID as y8_,
e3_.ID as y9_,
this_.APPROVED as y10_
from
ABSENCE this_
left outer join
CONTRACT c1_
on this_.CONTRACT_ID=c1_.ID
left outer join
PERSON p2_
on c1_.PERSON_ID=p2_.ID
left outer join
DOSSIER md4_
on p2_.ID=md4_.PERSON_ID
left outer join
CODE type5_
on md4_.DOSSIER_TYPE_CD=type5_.ID
left outer join
CODE s6_
on this_.STATUS_CD=s6_.ID
left outer join
WA_EXPERTISE e3_
on this_.WA_EXPERTISE_ID=e3_.ID
left outer join
PI_EXPERTISE e3_
on this_.PI_EXPERTISE_ID=e3_.ID
where
type5_.CODE='A'
and p2_.FIRST_NAME like 'x'
order by
this_.START_DT asc
Any tips on how to fix the duplicate naming (e3_) in the above?
Thanks in advance
(Using Oracle 10g & Hibernate 3.2.6)