-->
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.  [ 8 posts ] 
Author Message
 Post subject: Lazy many to one
PostPosted: Tue Sep 06, 2005 2:53 am 
Senior
Senior

Joined: Sat Sep 10, 2005 3:46 pm
Posts: 178
Can someone tell me if a many to one relationship is lazy loaded by default?

Is there any way to manage the way that a many to one relationship is loaded? For instance, can I cause it to be loaded with the default fetch group or cause it to be lazy loaded depending on my situation?

I was looking fo the lazy attribute of the many-to-one mapping but couldn't find it.

Thanks for any help.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 06, 2005 8:37 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
many to one is not lazy loaded by default.

Once lazy loading is enabled (using <class name="..." lazy="true">), you can force its loading by using fetch...

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 06, 2005 1:34 pm 
Senior
Senior

Joined: Sat Sep 10, 2005 3:46 pm
Posts: 178
Ok I see, so I have to place the lazy attribute on the class itself. I looked through the documentation but must have missed the section on the ability to fetch a lazy class on the initial select. Are you referring to batching?

Could you point me in the right direction? Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 07, 2005 11:53 am 
Contributor
Contributor

Joined: Thu May 12, 2005 9:45 am
Posts: 593
Location: nhibernate.org
Read 9.3. Associations and joins

_________________
Pierre Henri Kuaté.
Get NHibernate in Action Now!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Sep 07, 2005 12:43 pm 
Senior
Senior

Joined: Sat Sep 10, 2005 3:46 pm
Posts: 178
Thank you.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 08, 2005 12:42 pm 
Newbie

Joined: Thu Sep 08, 2005 12:15 pm
Posts: 17
Hi,

im using nhibernate in my project for 2 month now, and im trying to improve the perfomance of my web app.

The thing is that i have a class with a lot of many-to-one relationship. And the performance have drop significantly.

In my app i have to display a list of media(tv, radio etc) and when i have under 50 result to display its not so bad but when its 150 result it take like 15 sec to display the list. All the collections are lazyloaded but I would like to lazyload almost every member of the class.

So I found this post on the forum and I read the documentation about the lazy load attribute of the <class> tag and the proxy attribute. But after reading the doc i still not understand how the proxy attribute works and what should it be equal to.

I tried to put the proxy = to my class name and make the properties virtual in my class, but when i run the apps and look in my dropdownlist I have the Id of the object instead of the string that should appear. When i put the proxy attribute I don t understand what im i doing. Can anybody explain it to me or give me an url of a more detail documentation about this please.

Thank you
Simon

here s the mapping of my Media Class



Code:
   <class name="Datablitz.Engine.objets.BaseMedia, Datablitz.Engine" table="Media">
      <jcs-cache usage="read-write"/>
      <id name="IdMedia" column="IdMedia" type="Int32">
         <generator class="identity" />
      </id>
      <property name="Nom" column="Nom" type="String" length="75"/>
      <property name="SiteWeb" column="SiteWeb" type="String" length="75"/>
      <property name="Courriel" column="Courriel" type="String" length="75"/>
      
      <bag name="Adresses" table="JN_Media_Adresse" lazy="true">
         <jcs-cache usage="read-write"/>
         <key column="IdMedia"/>
         <many-to-many class="Datablitz.Engine.objets.Adresse, Datablitz.Engine" column="IdAdresse"/>
      </bag>
      
      <set name="Categories" table="JN_Media_Categorie" lazy="true">
         <jcs-cache usage="read-write"/>
         <key column="IdMedia"/>
         <many-to-many class="Datablitz.Engine.objets.Categorie, Datablitz.Engine" column="IdCategorie"/>
      </set>
      
      <set name="Langues" table="JN_Media_langue" lazy="true">
         <jcs-cache usage="read-write"/>
         <key column="IdMedia"/>
         <many-to-many class="Datablitz.Engine.objets.Langue, Datablitz.Engine" column="IdLangue"/>
      </set>
      
      <set name="Telephones" table="JN_Media_Telephone" lazy="true">
         <jcs-cache usage="read-write"/>
         <key column="IdMedia"/>
         <many-to-many class="Datablitz.Engine.objets.Telephone, Datablitz.Engine" column="IdTelephone"/>
      </set>
      
      <set name="Ethnies" table="JN_Media_Ethnies" lazy="true">
         <jcs-cache usage="read-write"/>
         <key column="IdMedia"/>
         <many-to-many class="Datablitz.Engine.objets.Ethnie, Datablitz.Engine" column="IdEthenies"/>
      </set>
      
      <many-to-one name="TypeMedia" class="Datablitz.Engine.objets.TypeMedia, Datablitz.Engine" column="IdTypeMedia" not-null="true" />
      <many-to-one name="TypeAudience" class="Datablitz.Engine.objets.TypeAudience, Datablitz.Engine" column="IdTypeAudience" not-null="true" />
      <many-to-one name="TypeTerritoireCouvert" class="Datablitz.Engine.objets.TypeTerritoireCouvert, Datablitz.Engine" column="IdTypeTerritoireCouvert" not-null="true" />
      <many-to-one name="Note" class="Datablitz.Engine.objets.Note, Datablitz.Engine" column="IdNote" not-null="true" />
      <many-to-one name="Proprietaire" class="Datablitz.Engine.objets.BaseMedia, Datablitz.Engine" column="IdProprietaire" not-null="true"/>
      
      <joined-subclass name="Datablitz.Engine.objets.MediaRadio, Datablitz.Engine" table="MediaRadio">                
                   <key column="IdMedia"/>
                    <property name="Frequence" type="String" column="Frequence" length="10"/>
                    <property name="Puissance" type="Int32" column="Puissance"/>
                    <property name="StyleMusique" type="String" column="StyleMusique" length="50"/>
                    <property name="GroupeAge" type="String" column="GroupeAge" length="50"/>
                    <many-to-one name="TypeBande" class="Datablitz.Engine.objets.TypeBande, Datablitz.Engine" column="IdTypeBande" not-null="true" />
               <many-to-one name="TypeProfilRadio" class="Datablitz.Engine.objets.TypeProfilRadio, Datablitz.Engine" column="IdTypeProfilRadio" not-null="true" />
               <many-to-one name="TypeCibleRadio" class="Datablitz.Engine.objets.TypeCibleRadio, Datablitz.Engine" column="IdTypeCibleRadio" not-null="true" />
        </joined-subclass>
       
   </class>


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 08, 2005 5:07 pm 
Regular
Regular

Joined: Tue May 24, 2005 12:55 pm
Posts: 56
First, You don't have to set the Proxy attribute on a class node when you have the lazy attribute set to True. If you have the class set to be lazy, the property nodes (bag, set, map, many-to-one, ...) are set to be lazy and the properties in the class are virtual it should be lazy loading. I've not seen any performance issues with this setup.

Second, How do you know it isn't lazy loading?

Third, Not sure if I understand your usage, but if you are listing items that are all being lazy loaded, I have found that it slows performance if there is a lot of lazy loading per session. I've compared this against some *legacy* datasets that get all the data up front and they are always faster than NH with alot of lazy loading. It is best to join fetch in a HQL query when you need a number of lazy properties at once. This get NH performance on par with datasets, not quite equal but very close.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 08, 2005 6:24 pm 
Senior
Senior

Joined: Sat Sep 10, 2005 3:46 pm
Posts: 178
Is there anyway to cause a lazy loaded object to always be loaded on a particular assosciation without using a join fetch?

The reason I ask this is that I have a class set to be lazy loaded. This is fine for most assosciations, but this one particluar assosciation always navigates to the class. A join fetch is ok, but I have realized that I can't use the simple session.Get operation anymore if I want to use the load the assosciated object right away.

is there not a way to indicate that this particlular assosciation should always be fetched with the object?

I thought that the outer-join attribute on the many to one mapping was the way to go because the documentaiton says this for outer-join="true": Always fetch the association using an outerjoin

I guess my understandaing of outer-join is not very accurate. Thanks for any help.


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