(I think Google Groups ate my previous reply so I'm reposting)

I'm using NH 2.1.1.4000 (the version bundled with Sharp Architecture
2009Q3 release).

The source code I was looking at was trunk HEAD revision from the NH
sourceforge site as of last night.

On Feb 23, 9:54 am, David Archer <[email protected]> wrote:
> Not sure if this helps but I just checked the Hibernate trunk from SF
> and it has the same behavior of reusing child sessions per entity mode
> when calling ISession.GetSession(EntityMode).
>
> Digging a little deeper, it seems that Dispose in NH just calls Close
> which then will Close all the child sessions.
>
> So should the recommended usage pattern for child sessions be to not
> close/dispose of them but rather to rely on the parent/root session
> being disposed?
>
> i.e.
>
> using (ISession session = OpenSession())
> using (var tx = session.BeginTransaction())
> {
>         var entity = new DomainClass();
>         session.Save(entity);
>
>         // In Event Listener #1
>         var otherSession = session.GetSession(EntityMode.Poco)
>         otherSession.Save(new DomainClass());
>         otherSession.Flush();
>
>         // In Event Listener #2
>         var anotherSession = session.GetSession(EntityMode.Poco) //
> anotherSession == otherSession due to child session sharing
>         anotherSession.Save(new DomainClass());
>         anotherSession.Flush();
>
>         tx.Commit();}
>
> // all 3 sessions are closed at this point
>
> On Feb 23, 12:33 am, Fabio Maulo <[email protected]> wrote:
>
>
>
> > To which version are you looking ?
>
> > 2010/2/23 David Archer <[email protected]>
>
> > > Hello,
>
> > > I have two IPreUpdate event listeners that both need to save
> > > additional entities at the time another entity is updated.
>
> > > To perform this in each listener, I open a child session, save the
> > > entity, and flush the child session. However, if I dispose of the
> > > child session in the event listeners, I get a "Session is Closed!"
> > > error when the second listener runs.
>
> > > Looking at the code in NH trunk, the child sessions are being re-used
> > > based on EntityMode which explains why this is happening. Are there
> > > any reasons why NH couldn't actually create a new child session each
> > > time?
>
> > > Secondly, I want to ask a question about the summary comment for
> > > ISession.GetSession(EntityMode entityMode) that shows up in
> > > intellisense:
> > > ===
> > > Starts a new Session with the given entity mode in effect. This
> > > secondary
> > > Session inherits the connection, transaction, and other context
> > > information from the primary Session. It doesn't need to be flushed
> > > or closed by the developer.
> > > ===
>
> > > Why does it says the child session "doesn't need to be flushed"? In at
> > > least my specific example, if I don't flush the child session, the
> > > entities I save never get persisted.
>
> > > Thanks!
>
> > > --
> > > 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]<nhusers%[email protected]
> > >  >
> > > .
> > > For more options, visit this group at
> > >http://groups.google.com/group/nhusers?hl=en.
>
> > --
> > Fabio Maulo

-- 
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