Fabio,

It is quite possible I am missing something here but I'm not seeing
any code in the SessionImpl.GetSession(EntityMode) function that would
cause me to always get a new child session.

Here is the content of that function from trunk:

===

public ISession GetSession(EntityMode entityMode)
{
        using (new SessionIdLoggingContext(SessionId))
        {
                // This is explicitly removed to allow support
                // for child sessions that want to flush during
                // the parent session lifecycle. See NH-1714,
                // and the suggested audit examples.
                //
                //if (this.entityMode.Equals(entityMode))
                //{
                //    return this;
                //}

                if (rootSession != null)
                {
                        return rootSession.GetSession(entityMode);
                }

                CheckAndUpdateSessionStatus();

                ISession rtn = null;
                if (childSessionsByEntityMode == null)
                {
                        childSessionsByEntityMode = new Dictionary<EntityMode, 
ISession>();
                }
                else
                {
                        if (childSessionsByEntityMode.ContainsKey(entityMode))
                                rtn = childSessionsByEntityMode[entityMode];
                }

                if (rtn == null)
                {
                        log.DebugFormat("Creating child session with {0}", 
entityMode);
                        rtn = new SessionImpl(this, entityMode);
                        childSessionsByEntityMode.Add(entityMode, rtn);
                }

                return rtn;
        }
}

===

On Feb 23, 11:46 am, Fabio Maulo <[email protected]> wrote:
> but there is a difference with what you are explaining in your first post.
> The code you have saw, does not reuses the session depending on EntityMode,
> instead, the child session is always a new session.
>
> perhaps we should review the doc....
>
> 2010/2/23 David Archer <[email protected]>
>
>
>
>
>
> > On my project, I'm using NHibernate 2.1.1.4000 (the version bundled
> > with Sharp Architecture 2009Q3 release).
>
> > The NH sources I was looking at were from trunk (https://
> > nhibernate.svn.sourceforge.net/svnroot/nhibernate/trunk/nhibernate)
> > HEAD revision as of last night.
>
> > David Archer
>
> > 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]
> > > >  >
> > <nhusers%[email protected]<nhusers%252bunsubscr...@googlegroup 
> > s.com>>
> > > > .
> > > > 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]<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