It does solve the problem, but has pretty significant performance  
implications in "common" use cases, which is why it's not the  
default.  Obviously it's hard to say what is best without seeing the  
code, but I'd say the default (just get them all) is probably best,  
unless the category tree is really broad.  Fetching a bit more data  
than you need with a single query is usually better than fetching  
exactly the right amount of data at really fine granularity with a lot  
of little queries.  The connection/query overhead is more expensive  
than the return data transfer.  Ideally you'd get both (exact right  
data in a single query), however since you use your objects in lots of  
different ways but only get to map them once, you have to generalize a  
bit.  Or you can make everything lazy and do all ops with HQL, which  
would be as "perfect" as SQL, but with all the downsides and more, so  
don't do that. :)

Sorry for how run-on that is.  Hard to do editing on the phone, so I  
just kind of streamed it out.

cheers,
barneyb

--
Barney Boisvert
bboisv...@gmail.com
http://www.barneyb.com/

On Jan 17, 2010, at 9:52 PM, Raymond Camden <rcam...@gmail.com> wrote:

>
> I'm confused - are you saying this _doesn't_ solve the problem - or
> has side effects if he doesn't use it as described? Or are you saying
> that it is best to just get em all at once?
>
> On Sun, Jan 17, 2010 at 10:19 PM, Barney Boisvert  
> <bboisv...@gmail.com> wrote:
>>
>> lazy=proxy gives you N+1 behaviour for your collection.  That is, if
>> you need a Category and it's 10 subcategories, you'll end up doing 11
>> queries (one to retrieve each row individually).  Of course, if you
>> only use the category and three children you'll only run 4 queries.
>> But if you do an eager fetch of the subcategories (the default),
>> you'll run a single query.  Period.  Yes, it'll be wider, but it's a
>> single query and therefore avoids a significant amount of overhead
>
> 

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Want to reach the ColdFusion community with something they want? Let them know 
on the House of Fusion mailing lists
Archive: 
http://www.houseoffusion.com/groups/cf-talk/message.cfm/messageid:329747
Subscription: http://www.houseoffusion.com/groups/cf-talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4

Reply via email to