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
|