-->
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.  [ 10 posts ] 
Author Message
 Post subject: Load all lazy properties at once
PostPosted: Fri Apr 27, 2007 11:46 am 
Newbie

Joined: Fri Apr 27, 2007 11:41 am
Posts: 9
hi @ all
i wonder if there is a function to load all lazy properties of an object at once. right now i iterate with reflection through all properties and initialize each of them seperate, but that is quite time consuming. is there a better way?

greez simon


ps: i am using NHibernate 1.2.0


Top
 Profile  
 
 Post subject:
PostPosted: Fri Apr 27, 2007 2:56 pm 
Senior
Senior

Joined: Sat Sep 10, 2005 3:46 pm
Posts: 178
lazy="false" in the mapping


Top
 Profile  
 
 Post subject:
PostPosted: Sat Apr 28, 2007 4:36 am 
Newbie

Joined: Fri Apr 27, 2007 11:41 am
Posts: 9
yes sure, but that is not really what i want. i do not want to load all the properties every time i load the object.
i load a list of objects and display them in a list. if the user chooses one of them, then i like to load all its lazy properties. not of all object in the list!


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 29, 2007 3:40 am 
Regular
Regular

Joined: Tue Feb 21, 2006 9:50 am
Posts: 107
normally we use views to display lists of data. The view contains the primary key of the detail data. If the user selects a line the detail data will be read via the primary key. The view contains only the nessecary data. If the data has to be read via joins from multiple tables these joins are precompiled and processed on the database server which reduces the traffic between the client and the server. You can map views like tables with NHibernate.

Regards
Klaus


Top
 Profile  
 
 Post subject:
PostPosted: Sun Apr 29, 2007 6:07 am 
Regular
Regular

Joined: Thu Nov 23, 2006 10:29 am
Posts: 106
Location: Belgium
Hello,

I didn't test it, but wouldn't NHibernateUtil.Initialize(<object>) do this ?
You'll have to Lock() or Refresh() your object prior to doing this, of course.

_________________
Please rate this post if it helped.

X.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 30, 2007 8:21 am 
Newbie

Joined: Fri Apr 27, 2007 11:41 am
Posts: 9
no, unfortunately that does not work :-(

@ luedi: yes that would probably be the most preferred solution, but i need all the objects before... don't ask why! :-)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 30, 2007 9:39 am 
Senior
Senior

Joined: Sat Apr 21, 2007 11:01 pm
Posts: 144
How about using eager fetching?
There is a breif point on it in the "best practices" section of the hibernate docs, although it does say not to do it. lol :P
Quote:
Prefer lazy fetching for associations.
Use eager (outer-join) fetching sparingly. Use proxies and/or lazy collections for most associations to classes that are not cached at the JVM-level. For associations to cached classes, where there is a high probability of a cache hit, explicitly disable eager fetching using outer-join="false". When an outer-join fetch is appropriate to a particular use case, use a query with a left join fetch.

http://www.hibernate.org/hib_docs/refer ... tices.html

_________________
Everytime you get an answer to your question without giving credit; god kills a kitten. :(


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 30, 2007 4:45 pm 
Senior
Senior

Joined: Sat Sep 10, 2005 3:46 pm
Posts: 178
if you want to override the fetching specified in the mapping files then use a fetch join

Code:
from Eg.Cat as cat
    inner join fetch cat.Mate
    left join fetch cat.Kittens


or specify the fetch group through the criteria api

Code:
IList cats = sess.CreateCriteria(typeof(Cat))
    .Add( Expression.Like("Name", "Fritz%") )
    .SetFetchMode("Mate", FetchMode.Eager)
    .SetFetchMode("Kittens", FetchMode.Eager)
    .List();



of course all this is in the docs.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 16, 2007 6:33 am 
Newbie

Joined: Fri Apr 27, 2007 11:41 am
Posts: 9
thanks a lot! eager was a good hint. i still iterate with reflection through all properties, but now i can load them all at once.

greez simon


Top
 Profile  
 
 Post subject:
PostPosted: Fri May 18, 2007 1:40 pm 
Senior
Senior

Joined: Sat Sep 10, 2005 3:46 pm
Posts: 178
not sure what you are using relfection for on your properties but you can check if a lazy loaded assosciation is initialiazed ot not with

Code:
NHibernateUtil.IsInitialized


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