-->
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: how lazy = proxy work?
PostPosted: Mon Feb 20, 2006 12:49 am 
Beginner
Beginner

Joined: Fri Jan 13, 2006 11:19 am
Posts: 24
Quote:
lazy (optional - defaults to proxy): By default, single point associations are proxied. lazy="true" specifies
that the property should be fetched lazily when the instance variable is first accessed (requires
build-time bytecode instrumentation). lazy="false" specifies that the association will always be eagerly
fetched.


How the proxy work actually? I totally can not see the hsql query in console but i can get the data. How can i enable the lazy=true? Which one is better proxy or laxy = true.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Feb 20, 2006 5:05 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
As I understand it, the different between lazy="true" and lazy="proxy" is that lazy="true" is property-level laziness, but ="proxy" is entity level. That is, when you access any property in an entity that has been retrieved via a default/lazy="proxy" association, the whole entity is initialized, except for properties that are lazy="true"; they're not retrieved from the database until they are accessed.

The default is better in most cases, because the most common situation is that you want all/most of the fields in an entity, and there's no point in going to the database once per property. For very large fields, blobs, clobs, etc., you might want to set lazy="true", so that the data is not retrieved unless actually needed.

(Note that in 3.1, lazy="true" has been renamed to lazy="no-proxy", presumably to reduce this sort of confusion)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 21, 2006 9:49 am 
Beginner
Beginner

Joined: Fri Jan 13, 2006 11:19 am
Posts: 24
How come the hibernate reference book does not talk about the thing that you mentionded here? Whe can i find this tutorial?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 21, 2006 6:02 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
That's probably because hibernate is updated faster than the book is reprinted :) Read the ref docs of each version, as they come out.

In the 3.1 ref docs, sections 5.1.10 (brief) and 19 (whole thing) are the bits to read. Compare those with sections 6.1.10 and 20 in the 3.0 ref docs.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 23, 2006 1:18 am 
Beginner
Beginner

Joined: Fri Jan 13, 2006 11:19 am
Posts: 24
I am talking about many to one association.

1) I am using hibernate 3.0.5. I still do not understand the lazy=proxy VS lazy=true.

2) I will get red line in eclispe when i set the lazy="true"? But it exists in reference book.
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">

2) I can not see the query if i set lazy=proxy. Why?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 23, 2006 4:59 pm 
Expert
Expert

Joined: Thu Dec 23, 2004 9:08 pm
Posts: 2008
2) The 3.0 DTD at sourceforge doesn't mention the lazy attribute on many-to-one at all. Strange. In the downloaded source code, the 3.0 DTD in the 3.1.1 release doesn't allow lazy="true", but does allow lazy="no-proxy", which is the new name for the same thing. In the 3.0.5 release, the 3.0 DTD allows lazy="true". Eclipse's red line is probably dependent on which version of the DTD it's looking at.

1 + 2(b)) lazy="proxy" means that when any member of the proxied object is queried, the whole object is retrieved in one select statement. Until then, a fake (CGLib) version of the object is used. Any values that hibernate puts into the fake version (notably, the ID) are valid values, and when they're accessed, hibernate does not de-proxy the object. lazy="true" or lazy="no-proxy" issues the select as soon as the object is accessed.

This is from the ref docs, section 19.1:
Quote:
"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.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 09, 2006 12:07 pm 
Beginner
Beginner

Joined: Fri Jan 13, 2006 11:19 am
Posts: 24
Anyone can tell me why can not see the query if i set lazy=proxy but i can get the object. Why?


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.