-->
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.  [ 4 posts ] 
Author Message
 Post subject: hibernate.max_fetch_depth
PostPosted: Wed Mar 10, 2004 7:23 pm 
Newbie

Joined: Sun Feb 01, 2004 3:28 am
Posts: 11
I have a question about Hibernate's max_fetch_depth property. My understanding of the property is that it will limit the number of tables that Hibernate will query in an outer join. So, for example, if I have:

table CUSTOMER {
CUSTOMER_ID,
CUSTOMER NAME,
CUSTOMER_COUNTY_ID (references COUNTY_ID)
}

table COUNTY {
COUNTY_ID,
COUNTY_NAME,
COUNTY_STATE_ID (references STATE_ID)
}

table STATE {
STATE_ID,
STATE_NAME
}



and if I set hibernate.max_fetch_depth = 1, do a select on CUSTOMER, then I won't get the STATE object. In order to get the STATE object, I would have to set hibernate.max_fetch_depth = 2.

I know it's much simpler and a much better idea to try this out myself, rather than post to the forum. I actually did try this, and it's not acting the way I expected, so I think I'm misunderstanding this property. The relevant information for the example I tried is below:

table CONTACT {
SOME PROPERTIES [ ],
CUSTOMER_ID,
CONTACT_COUNTY_ID (references COUNTY)
}

table CUSTOMER {
SOME PROPERTIES [ ]
}

table COUNTY {
COUNTY_ID,
COUNTY_STATE_ID (references STATE)
CONTACT_ID (references CONTACT)
}

table STATE {
STATE_ID
}

In my test, I retrieve an object from CUSTOMER that matches a specific record. I know this schema doesn't make much sense, it was just developed to see how Hibernate would react in certain situations (i.e., the circular reference, which it seems to handle beautifully). Anyway, with hibernate.max_fetch_depth = 1, Hibernate returns:

<ctc-list>
<ctc>
<uid>25</uid>
<id>CTC024</id>
<surname>Hops</surname>
<forename>Shawn</forename>
<middlename>Ian</middlename>
<formatted-name>0</formatted-name>
<title>Mr.</title>
<gender>M</gender>
<phone>1234567890 112</phone>
<fax>1234567890</fax>
<email>sih@epack.com</email>
<usr-created-by>5</usr-created-by>
<usr-updated-by>3</usr-updated-by>
</ctc>
<ctc>
<uid>26</uid>
<id>CTC026</id>
<surname>Zappa</surname>
<forename>Frank</forename>
<formatted-name>Zappa, Frank</formatted-name>
<title>Mr.</title>
<gender>M</gender>
<phone>4022344249</phone>
<fax>1234567890</fax>
<city>Omaha</city>
<email>fzappa@hotmail.com</email>
<cty-code>
<code>SARPY</code>
<desc>Sarpy County</desc>
<ctc-uid>
<uid>12</uid>
<id>CTC011</id>
<cus-uid>
<uid>3</uid>
<id>CUS003</id>
<name>Time Square Deli</name>
<address>4948 Chicago Drive</address>
<state>CA</state>
<city>Bieber</city>
<pcd-code-home>
<code>abc12</code>
</pcd-code-home>
<phone>1223674234</phone>
<date-created>2037-07-04T00:00:00.000-07:00</date-created>
<usr-created-by>3</usr-created-by>
<usr-updated-by>6</usr-updated-by>
</cus-uid>
<surname>Schroeder</surname>
<forename>Mike</forename>
<middlename>Brian</middlename>
<formatted-name>0</formatted-name>
<title>Mr.</title>
<gender>M</gender>
<phone>1234567890 112</phone>
<fax>1234567890</fax>
<city>Boston</city>
<email>mbs@deli.com</email>
<date-created>2037-07-04T00:00:00.000-07:00</date-created>
<usr-created-by>3</usr-created-by>
<usr-updated-by>6</usr-updated-by>
</ctc-uid>
</cty-code>
</ctc>
</ctc-list>
<cus>
<uid>10</uid>
<id>CUS010</id>
<name>Epack</name>
<address>1878 Mountain Road</address>
<state>CA</state>
<city>Redding</city>
<pcd-code-home>
<code>123</code>
</pcd-code-home>
<phone>182654993</phone>
<note>Epack is looking for a security package for the
online user community</note>
<usr-created-by>2</usr-created-by>
<usr-updated-by>3</usr-updated-by>
</cus>
</customer-with-contacts>
</record-list>
<message-list/>
</result>

Is my understanding of this property not correct, or am I somehow mishandling the implementation of the property? Any help would really be appreciated!

--Charles


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 12, 2004 1:50 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
How do you requesr and what is the SQL produced ?

Hibernate will limit the number of outer join in 1 request (it'll not lazy load property if it reach the limit).

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 12, 2004 6:18 pm 
Newbie

Joined: Sun Feb 01, 2004 3:28 am
Posts: 11
Emmanuel,

Thank you very much for your reply!

To respond to your questions:

I request the data by using the uniqueResult() method on the Criteria object.

As far as the SQL goes, it's VERY lengthy and the actual design of the db is proprietary, so I'm somewhat hesistant to post to the forum. Can I email it to you?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 12, 2004 8:37 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
You are trying to use max_fetch_depth in a way it is not intended for. The point of this property is not to tune fetching strategies for particular associations - there is association-level metadata for that. max_fetch_depth specifies the maximum depth we will ever fetch into the object graph. This can occasionally be slightly unpredictable. It certainly does not put a bound in the number of outer joins!


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