-->
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.  [ 6 posts ] 
Author Message
 Post subject: should lazy loading be faster than manually loading children
PostPosted: Wed Oct 01, 2008 3:57 pm 
Newbie

Joined: Sat Jun 28, 2008 6:26 am
Posts: 4
Hi guys,

I've been banging my head over this little problem for a while now and thought it was time to hit the forums.

I'm experiencing some strange behaviour with nhibernate, well at least I think so. We have a parent object which contains two lists of child objects. Both lists are populated from the same table however are filtered by a few columns and loaded into their respective Property.

These child objects were loaded lazily however, if multiple requests came in for the parent object, with different filter criteria nhibernate would load all parent objects with the latest requested filter.

Because of this we decided to manually load these lists when they were required which was not a huge change and worked fine. However when running our time tests they started to fail. It looks like this change has more than doubled the loading times for this data.

My question is this: When loading the child objects manually through a session, should this be slower than using lazy loading.


Thanks in advance,

Craig


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 02, 2008 2:41 am 
Regular
Regular

Joined: Tue Jul 29, 2008 3:30 am
Posts: 74
How do you load the lists?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 02, 2008 4:33 am 
Newbie

Joined: Sat Jun 28, 2008 6:26 am
Posts: 4
Below is the method in our DAO object to return the list.

FutureResidual is the child object, RegistrationYear/Month is how we decide which property the data should be loaded in

Code:
       
public IList<FutureResidual> GetUsedFutureResiduals(int dataset, Derivative derivative)
        {
            return CreateCriteria("FutureResidual")
                .Add(Expression.Eq("DerivativeId", derivative.Id))
                .Add(Expression.Eq("DataProviderId", dataset))
                .Add(Expression.Ge("RegistrationYear",0))
                .Add(Expression.Ge("RegistrationMonth",0))
                .AddOrder(Order.Desc("RegistrationYear"))
                .AddOrder(Order.Desc("RegistrationMonth"))
                .AddOrder(Order.Asc("FinanceTerm"))
                .AddOrder(Order.Asc("MileageAtEndOfAgreement"))
                .List<FutureResidual>();
        }


We then put this list into the parent object


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 02, 2008 4:52 am 
Regular
Regular

Joined: Tue Jul 29, 2008 3:30 am
Posts: 74
Wow, that's rather complex for a simple list of a entity.

Could you post your mapping file(s)?
Do you have enabled show_sql and checked if NHibernate does any additional (unwanted) queries?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 02, 2008 7:11 am 
Newbie

Joined: Sat Jun 28, 2008 6:26 am
Posts: 4
it's just a simple select with a few where clauses, the orders are there for optimisation, the sql executed is the same as when lazy loading.

Code:
<hibernate-mapping    assembly="Codeweavers.VehicleData.Core" namespace="Codeweavers.VehicleData.Core.BusinessObjects"
   xmlns:xsd="http://www.w3.org/2001/XMLSchema"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns="urn:nhibernate-mapping-2.2">

  <class name="FutureResidual" table="future_residuals">
    <id name="Id" column="id" type="Int32" unsaved-value="0">
      <generator class="native"/>
    </id>

    <property name="DerivativeId" column="derivative_id" type="Int32"/>
    <property name="RegistrationYear" column="registration_year" type="Int32"/>
    <property name="RegistrationMonth" column="registration_month" type="Int32"/>
    <property name="FinanceTerm" column="finance_term" type="Int32"/>
    <property name="Value" column="future_residual" type="Decimal"/>
    <property name="VehicleTypeId" column="vehicle_type_id" type="Int32"/>
    <property name="DataProviderId" column="data_provider_id" type="Int32"/>
    <component name="MileageAtEndOfAgreement" class="Mileage">
      <property name="Value" column="mileage_at_end_of_agreement" type="Decimal"/>
    </component>

  </class>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 02, 2008 9:08 am 
Regular
Regular

Joined: Tue Jul 29, 2008 3:30 am
Posts: 74
I was more interested in the mapping of Derivative ;-)

But if the executed SQL is the same I really don't have any idea why this could be slower than the default lazy loading.


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