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.  [ 2 posts ] 
Author Message
 Post subject: NHibernateUtil.Initialize() and No Session
PostPosted: Tue Oct 23, 2007 7:19 am 
Newbie

Joined: Tue Aug 28, 2007 1:01 pm
Posts: 8
Location: Indonesia
Hibernate version: 1.2.0 GA

Name and version of the database you are using: Microsoft SQL Server 2005 Standard Edition SP2

I've just read the NHibernate docs (http://www.hibernate.org/hib_docs/nhibe ... tions.html) which states:
6.5. Lazy Initialization
"...Usually, the application calls NHibernateUtil.Initialize() for each collection that will be needed in the web tier (this call must occur before the session is closed) or retrieves the collection eagerly using a NHibernate query with a FETCH clause..."

I actually don't understand the following statement: "this call must occur before the session is closed".

I think I need a clearer explanation of what the consequences are of calling it when no session exists. I'm questioning this since I'm practicing with it in my current (Windows Forms) application and it works just fine so far. CMIIW.

Thanks before!


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 23, 2007 9:13 am 
Regular
Regular

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

The idea is to:
a) mark your collections as lazy
b) buildup your object in the business layer
c) send the object to the presentation layer

It is in (b) that you have to make sure that all collections are initialized before sending your object to the presentation layer because the scope of a Session is supposed to be very small and is not meant to be extended to the presentation layer.

If the session is closed and you try to use a lazy-loaded collection, you'll get an exception.

The fact that you don't get an exception means that:
- the collections are not marked as lazy=true
or
- the Session is in fact not closed at the moment that you're using the lazy collections for the first time

_________________
Please rate this post if it helped.

X.


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