-->
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.  [ 5 posts ] 
Author Message
 Post subject: Is Lazy Fetching Always Good?
PostPosted: Sat Mar 17, 2007 11:40 am 
Beginner
Beginner

Joined: Thu Mar 01, 2007 9:40 am
Posts: 23
Location: UK
Hi,

I'm quiet challenged by the idea of lazy fetching, especially in certain cases. I hear people saying to always use lazy fetching, and Hibernate 3 comes with lazy fetching true by default.

To me, lazy fetching is just a way of postponing the query execution a little longer.. maybe to another method.. but the query has to be executed to fetch the data.

If I have a scenario where-in I am sure that all the objects in my object graph will be used at some point within the application flow, should I be using lazy initialization, and leave my session open for long periods? I think it's better to fetch all the objects in the DAO itself, rather than postponing it to some other later, as I am damn sure that I require all the objects within the structure. In that case, I suppose, it's wise to go for non-lazy initialization.

Lemme know your thoughts on this.

--
Sam.

_________________
Sam.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 17, 2007 1:40 pm 
Regular
Regular

Joined: Sun Sep 17, 2006 2:48 am
Posts: 81
Location: California
Yes, I also agree to that. So in your case it makes perfect sense to avoid lazy loading. However in many scenarios, lazy loading makes sense where we dont know if say a collection would be required or not.


Top
 Profile  
 
 Post subject: How long is long?
PostPosted: Sun Mar 18, 2007 8:59 am 
Regular
Regular

Joined: Wed Aug 24, 2005 11:49 am
Posts: 63
Don't know how long your application flow is, but if you use lazy fetching (and transatction isolation to read-comnitted) you will get the data as it is on the moment of fetching.
Might be different if you use lazy and the fetch takes place at a later time and someone else committed data. (different user). Your non-lazy fetch might then be stale data!

_________________
Edwin van der Elst
Finalist IT Group


Top
 Profile  
 
 Post subject: Re: How long is long?
PostPosted: Sun Mar 18, 2007 12:20 pm 
Beginner
Beginner

Joined: Thu Mar 01, 2007 9:40 am
Posts: 23
Location: UK
evdelst wrote:
Don't know how long your application flow is, but if you use lazy fetching (and transatction isolation to read-comnitted) you will get the data as it is on the moment of fetching.
Might be different if you use lazy and the fetch takes place at a later time and someone else committed data. (different user). Your non-lazy fetch might then be stale data!


Well.... In my flow, i'm pretty sure nobody else will update the data between two requests. So, there's no scenario where-in another flow will update the same data.

_________________
Sam.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Mar 18, 2007 6:18 pm 
Beginner
Beginner

Joined: Wed Jan 03, 2007 7:47 pm
Posts: 23
Location: Richardson, Texas
Hello,

We also have use cases in our application in which we know up front that many of the objects will need to be loaded and some updated to peform the function.

I am planning to still define the entities with lazy fetching since loading the entire object graph is not always required. In those cases where this is required, I will define DAO queries to fetch the required objects.

Regards,
Kurt


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