-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Criteria: how to join three tables with single select?
PostPosted: Tue Jul 19, 2005 8:38 am 
Newbie

Joined: Tue Jul 19, 2005 7:58 am
Posts: 3
[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=?


Top
 Profile  
 
 Post subject: Re: Criteria: how to join three tables with single select?
PostPosted: Tue Jul 19, 2005 8:56 am 
Newbie

Joined: Tue Jul 19, 2005 7:58 am
Posts: 3
[quote="mgl]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?
[/quote]

the proper question is: how to get rid of the second, useless select?

regards,
M.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.