Don't disconnect the session NH will take care of closing/opening the
connection to optimize it to minimal usage time.

On Fri, Nov 7, 2008 at 3:18 PM, FrederikGheysels <
[EMAIL PROTECTED]> wrote:

>
> I am using NHibernate in a WinForms application.
> In this application, I make use of 'long sessions'; consider that I
> have an ISession that is kept around as long as my Form is open.
>
> That is:
> I load an object using this Session when the form is opened.
> When the form is being closed, I check if I have to save the object,
> and if so, I save it using the same session.
>
> During 'user think time', I disconnect the Session, so that the DB
> connection is not kept open for a long period of time.
>
> The issue that I now have, is that my object contains a collection
> which is lazy loaded.
> Since I disconnect my session once the object has been loaded, I get
> an exception offcourse when I want to access the collection of that
> object.  (I do not always need this collection).
>
> Therefore, when I need to access the collection, I explicitly
> reconnect the Session, and disconnect it afterwards.  Offcourse, this
> is not very 'transparant' IMHO.
> It would be nice if there would be some way to reconnect the session
> implicitly; the client should not even know that the collection that I
> want to retrieve, is a lazyloaded collection.
>
> I've tried creating an Intercepter, in where I've overriden the
> SetSession, Load and Instantiate methods.  In this way, I thought that
> I could reconnect the session each time the Load or Instantiate
> methods were invoked, and when I saw that the session was
> disconnected, I could reconnect the session.
> But, this doesn't work.
>
> Another option, would be that I keep my Session connected during 'user
> think time', but IMHO , this is not a viable option; one never knows
> how long the Form (and therefore the session) will be kept open, and
> connected to the DB.
>
> Is there any other way on how I could make this a bit more
> transparant ?
> Maybe it is an idea to add a method to the Interceptor which is
> invoked each time something is being lazy loaded (just before it is
> lazy loaded) ?
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to