Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Lazy loading and long NH sessions
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  5 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
FrenchC  
View profile  
 More options Apr 25 2008, 11:29 am
From: FrenchC <cres...@gmail.com>
Date: Fri, 25 Apr 2008 08:29:22 -0700 (PDT)
Local: Fri, Apr 25 2008 11:29 am
Subject: Lazy loading and long NH sessions
Hi all,
first of all, I'm a newbe to NH... Then: my problem is that I have to
entities: MupRuns and Mappings. The first one is the master entity and
the second one contains the children of each of the first one... When
I get access to the first one, if I set lazy="true" when I try to
dislpay the children of each of the master it return an error saying
that there is no session active...
To be precise consider that in the hbm.xml of the master the child is
setted as bag and in the master class the children list is setted as
an IList<Mappings>. Both these 2 entities aren't to be persisted on
the db...
Of course if I leave both 2 in lazy="false" all works fine, but the
performances decrease impressively...
Is there someone that can explain clearly and with some example how to
set a correct lazyloading?

Thx in advance
Francesco


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jason Meckley  
View profile  
 More options Apr 25 2008, 12:37 pm
From: Jason Meckley <jasonmeck...@gmail.com>
Date: Fri, 25 Apr 2008 09:37:15 -0700 (PDT)
Local: Fri, Apr 25 2008 12:37 pm
Subject: Re: Lazy loading and long NH sessions
the session needs to remain open to use lazy loading.
this would break.
IFoo foo;
using (SessionFactory.CreateSession())
{
               foo = session.Get<IFoo>(1)
}

foreach(IBar bar in Foo.Bars)
{
             bar.DoSomething();

}

this would not
IFoo foo;
using (SessionFactory.CreateSession())
{
             foo = session.Get<IFoo>(1)
             foreach(IBar bar in Foo.Bars)
             {
                          bar.DoSomething();
             }

}

On Apr 25, 11:29 am, FrenchC <cres...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Sheraz  
View profile  
 More options Apr 25 2008, 12:40 pm
From: Sheraz <sher...@gmail.com>
Date: Fri, 25 Apr 2008 09:40:06 -0700 (PDT)
Local: Fri, Apr 25 2008 12:40 pm
Subject: Re: Lazy loading and long NH sessions
Lazy loading means that you don't bring the associations when an
entity is loaded. But when you accessing the association (thru
properties), nHibernates goes and fetches if for you. In order for the
lazy loading to work, the session should be open. If it's not open
then you'd get that error. Also if you are using NH version 1.2 then
you don't need to set lazy=true as all associations are lazy by
default.
Example

ISession session = SessionFactory.OpenSession()
Master master = session.Load<Master>();//only master is loaded withoud
any associations
Children children = master.Children(); // lazily fetch children.
session.Close();

the children are fetched successfully as the session was open but if
you do this
ISession session = SessionFactory.OpenSession()
Master master = session.Load<Master>();//only master is loaded withoud
any associations
session.Close();
Children children = master.Children(); // lazily fetch children.

then you will get the error as the session is closed.
Hope that helps.

On Apr 25, 11:29 am, FrenchC <cres...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ian Joyce  
View profile  
 More options Apr 25 2008, 12:25 pm
From: "Ian Joyce" <ian.jo...@gmail.com>
Date: Fri, 25 Apr 2008 11:25:14 -0500
Local: Fri, Apr 25 2008 12:25 pm
Subject: Re: [nhusers] Lazy loading and long NH sessions
If your working in a web environment check out OpenSessionInView @
http://springframework.net/docs/1.1.1/reference/html/orm.html#orm-hib...

--Ian


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Sheraz  
View profile  
 More options Apr 26 2008, 6:24 pm
From: Sheraz <sher...@gmail.com>
Date: Sat, 26 Apr 2008 15:24:08 -0700 (PDT)
Local: Sat, Apr 26 2008 6:24 pm
Subject: Re: Lazy loading and long NH sessions
if you working with web then the best thing to do is store session in
HttpContext and use HttModule and open the sesion on load and close on
unload.

On Apr 25, 12:25 pm, "Ian Joyce" <ian.jo...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »