I have not understood that your intention was to work with 2 child sessions (3 in total) .
2010/2/24 David Archer <[email protected]> > I saw the comment about NH-1714 and understand it but maybe I'm not > explaining my issue correctly. > > What I am asserting is that if I run the following: > > === > var rootSession = OpenSession(); > var childSession1 = rootSession.GetSession(EntityMode.Poco); > var childSession2 = rootSession.GetSession(EntityMode.Poco); > === > > childSession1 and childSession2 will both be pointing to the same > Session object (which is a child session of the rootSession) due to > how the current GetSession implementation is using the > childSessionsByEntityMode dictionary to keep track of child sessions > based on EntityMode. > > The issue I'm seeing is that I can't dispose/close childSession1 > because if I do, I get an error when I try to flush childSession2. > > === > ISession rootSession = OpenSession(); > > var childSession1 = rootSession.GetSession(EntityMode.Poco); > childSession1.Dispose(); > > var childSession2 = rootSession.GetSession(EntityMode.Poco); > childSession2.Save(new DomainEntity()); > childSession2.Flush(); // I'll get a "session is closed" error here > === > > You said previously that "The code you have saw, does not reuses the > session depending on EntityMode, instead, the child session is always > a new session". I don't think this is true. While the change that is > commented in the code means that we don't re-use the parent session > (ie. return this), the rest of the function only creates a new child > session the FIRST time you call GetSession() for a particular > EntityMode. Subsequent calls to GetSession() with the same EntityMode > will return the same child session that was returned the first time > because it stores it in the (appropriately named) > childSessionsByEntityMode dictionary. > > > On Feb 24, 9:59 am, Fabio Maulo <[email protected]> wrote: > > try to have a look again because there is a comment explaining the > > difference with the previous implementation where GetSession for the same > > EntityMode return the same session ("return this"). > > > > 2010/2/23 David Archer <[email protected]> > > > > > > > > > > > > > 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%[email protected]>> > > > <nhusers%[email protected]<nhusers%[email protected]> > <nhusers%252bunsubscr...@googlegroup s.com>> > > > > > <nhusers%[email protected]<nhusers%[email protected]> > <nhusers%252bunsubscr...@googlegroup s.com> > > > <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]> > <nhusers%[email protected]<nhusers%[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]> > <nhusers%[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]<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.
