-->
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.  [ 4 posts ] 
Author Message
 Post subject: LazyLoad
PostPosted: Fri Jan 20, 2006 8:26 pm 
Newbie

Joined: Fri Jan 20, 2006 4:42 pm
Posts: 7
Really don't understand why NHibernate doesn't support lazyloading with closed session. Why?

And what effort it gets involved to enable this? Is it against the design somehow? I saw so many people crying for such a feature, and it has been never been addressed by anybody. What's the big deal to reopen a session to load the object? Is there anything wrong of doing this? Of is it possible at all?


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 21, 2006 3:46 am 
Regular
Regular

Joined: Mon Jul 18, 2005 4:10 am
Posts: 92
Location: Poland
Let me cite "Hibernate in Action" book here:

Quote:
Why can’t Hibernate open a new connection (or session) if it has to lazy-load
associations? First, we think it’s a better solution to fully initialize all
required objects for a specific use case using eager fetching (this
approach is less vulnerable to the n+1 selects problem). Furthermore,
opening new database connections (and ad hoc database transactions!)
implicitly and transparently to the developer exposes the application to
transaction isolation issues. When do you close the session and end the
ad hoc transaction—after each lazy association is loaded? We strongly
prefer transactions to be clearly and explicitly demarcated by the application
developer. If you want to enable lazy fetching for a detached
instance, you can use lock() to attach it to a new session.

_________________
michal


Top
 Profile  
 
 Post subject: LazyLoad
PostPosted: Tue Jan 24, 2006 4:42 pm 
Newbie

Joined: Fri Jan 20, 2006 4:42 pm
Posts: 7
The problem with LOCK is that I have to lock the owner of the instance, instead of the insteance itself, kindof weird and difficult to make it consistent..

michal wrote:
Let me cite "Hibernate in Action" book here:

Quote:
Why can’t Hibernate open a new connection (or session) if it has to lazy-load
associations? First, we think it’s a better solution to fully initialize all
required objects for a specific use case using eager fetching (this
approach is less vulnerable to the n+1 selects problem). Furthermore,
opening new database connections (and ad hoc database transactions!)
implicitly and transparently to the developer exposes the application to
transaction isolation issues. When do you close the session and end the
ad hoc transaction—after each lazy association is loaded? We strongly
prefer transactions to be clearly and explicitly demarcated by the application
developer. If you want to enable lazy fetching for a detached
instance, you can use lock() to attach it to a new session.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 25, 2006 5:12 am 
Regular
Regular

Joined: Mon Jul 18, 2005 4:10 am
Posts: 92
Location: Poland
You asked WHY it is done like this (no lazy loading after session close) - and I think the author of the book mentioned is right.

If lock cannot apply your problem maybe you should redesign your application and use eager fetching or at least NHibernateUtil.Initialize.

_________________
michal


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