[b]Problem:[/b]
Having relations between three entities
AInformation - one-to-one - BInformation - many-to-one - Classification
how to force Criteria to use joining between these tables in only one single select? For the attached mapping a second select is performed what becomes a problem when quering for not a single object but ie. the whole list. Adding setFetchMode(..., FetchMode.JOIN) does not help. Do you have any ideas?
regards,
M.
[b]Hibernate version: 3.0.5[/b]
[b]Mapping documents:[/b]
<class name="AInformation" table="XXX">
<composite-id class="Key" name="Key">
...
</composite-id>
<one-to-one fetch="join" name="BInformation" class="BInformation" outer-join="auto"/>
</class>
<class name="BInformation" table="YYY">
<composite-id class="Key" name="Key">
...
</composite-id>
<many-to-one fetch="join" not-found="ignore" outer-join="auto"
name="Classification" column="EYC" class="Classification" />
</class>
<class name="Classification" table="ZZZ">
<id name="gjc" type="string" />
<property name="gjd" type="string" />
</class>
[b]Code between sessionFactory.openSession() and session.close():[/b]
Criteria criteria = session.createCriteria(AInformation.class);
criteria.setMaxResults(1);
[b]The generated SQL (show_sql=true):[/b]
(1):
Hibernate: select this_.DADLNO as DADLNO2_, this_.DAIMPO as DAIMPO2_, i2_.EYDLNO as EYDLNO0_, i2_.EYIMPO as EYIMPO0_, i2_.EYC as EYC2_0_, cla3_.gjc as gjc1_, cla3_.gjd as gjd3_1_ from XXX this_ left outer join YYY i2_ on this_.DADLNO=i2_.EYDLNO and this_.DAIMPO=i2_.EYIMPO left outer join ZZZ cla3_ on i2_.EYC=cla3_.gjc where this_.DAIMPO=? fetch first 1 row only
(2):
Hibernate: select cla0_.gjc as gjc0_, cla0_.gjd as gjd3_0_ from ZZZ cla0_ where cla0_.gjc=?
|