-->
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.  [ 7 posts ] 
Author Message
 Post subject: Problem with outer-join
PostPosted: Wed Jul 14, 2004 3:49 pm 
Beginner
Beginner

Joined: Thu Jul 01, 2004 1:30 pm
Posts: 20
Location: Tucson, AZ
hibernate.max_fetch_depth=8

A-->B is a many-to-one relationship.

In the <many-to-one> tag of the mapping file for A, outer-join="true" is set.

In the Java application, I used HQL "from A" to get all objects of A and for each of them traverse the association A-->B to visit B. I am expecting a SQL statement to retrieve from an outer join of A and B. But what I saw in the debug mesg are separate SQL statements: first retrieve A objects and for each of them issue another SQL statement to get the B object associated with it. There were no outer join operators.

Can't we take advantage of outer join by object traversing instead of explicitly putting outer join operators in the HQL? Or am I missing anything?

Thank you!
Stan


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 15, 2004 7:05 am 
Expert
Expert

Joined: Fri Feb 06, 2004 7:49 am
Posts: 255
Location: Moscow, Russia
Try with eager fetching (chapter 7 of Hiberante In Action):
Code:
from A a
    inner join fetch a.b


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 15, 2004 7:06 am 
Expert
Expert

Joined: Fri Feb 06, 2004 7:49 am
Posts: 255
Location: Moscow, Russia
I meant left join fetch


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 15, 2004 7:22 am 
Expert
Expert

Joined: Fri Feb 06, 2004 7:49 am
Posts: 255
Location: Moscow, Russia
chapter 4 of Hibernate In Action:
"Keep in mind that eager fetching strategies declared in the mapping metadata are effective only if you use retrieval by identifier, ...."

As I understand the mapped outer-join="true" will work only with Session.load(), Session.get() and queries where you specify id in the WHERE clause. That is if you need real eager fetch specify it in HQL with inner join fetch, left join fetch or set via Criteria.setFetchMode("b", FetchMode.EAGER).

--
Leonid


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 15, 2004 7:38 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
whats after that comma is also important ", and navigating associations" :)

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 15, 2004 1:46 pm 
Beginner
Beginner

Joined: Thu Jul 01, 2004 1:30 pm
Posts: 20
Location: Tucson, AZ
Thank you for your answers! They are very helpful.
It is strange that I did not find the sentence you mentioned in the pdf version of "Hibernate in Action" ch4. Did it sometimes get revised recently?

But I did tried the session.get() and load() and they worked well. Then I tried ONLY s.get() to get an object of class A without navigating to B. It turned out that outer-join is still used. Yes, I have mapped B class as lazy="true".

I think it would be helpful to provide in the hibernate manual a conclusion of all the cases where eager fetch using outer-join is used. (if there is already such and I missed it, I apologize :)

Thanks,
Stan


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 15, 2004 2:03 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
"Keep in mind that eager fetching strategies declared in the mapping metadata are effective only if you use retrieval by identifier, use the criteria query API, or navigate through the object graph manually."

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.