-->
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.  [ 1 post ] 
Author Message
 Post subject: Many to One association lazy property options
PostPosted: Tue Sep 09, 2008 12:11 pm 
Senior
Senior

Joined: Fri Jun 01, 2007 12:41 pm
Posts: 121
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.


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

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.