I am trying to understand the different fetch strategies available for many-to-one relation in Hibernate.
http://www.hibernate.org/hib_docs/reference/en/html/performance.html#performance-fetching
Quote:
Proxy fetching - a single-valued association is fetched when a method other than the identifier getter is invoked upon the associated object.
"No-proxy" fetching - a single-valued association is fetched when the instance variable is accessed. Compared to proxy fetching, this approach is less lazy (the association is fetched even when only the identifier is accessed) but more transparent, since no proxy is visible to the application. This approach requires buildtime bytecode instrumentation and is rarely necessary.
many-to-one association lazy property has three values: "false", "proxy", "no-proxy".
Here is my bean. Person has Country as a property.
Person{
Country country;
}
<many-to-one not-null="true" name="country"/> <!--lazy loaded--->
<many-to-one not-null="true" lazy="proxy" name="country"/>
<many-to-one not-null="true" lazy="no-proxy" name="country"/>
I didn't find any difference between the country object loaded with Person. It is loaded as Country$$EnhancerByCGLIB$$4c622085 (id=58) in all the three cases.
Also, in all the cases country.getId() return a value. And If I try to access any other property lazy LazyInitializationException exception is thrown.
So what is advantage of having three options for lazy property.