As Jason said, it might be that you should avoid using multiple sessions. However, if you really want that, remember that when the first session is disposed all objects loaded using it loose their session association. You need to attach the object to the new session using e.g. SaveOrUpdate(), Update(), or Lock(), with proper arguments.
/Oskar 2010/9/15 PLen <[email protected]>: > The session that was used for the original query : > > using (ISession session = NHibernateHelper.OpenSession()) { > RptSource src = > testSession.CreateCriteria(typeof(RptSource)).Add(Restrictions.Eq("SourceId", > sourceid)).UniqueResult<RptSource>(); > byte barr = src.Body; > } > > was both disconnected and closed after the "using" statement (although > the session object itself was not null). If I accessed the Body > property before the end of the "using" statement, then all was well > because the session was still connected. As a test I tried the > following: > > using (ISession session = NHibernateHelper.OpenSession()) { > byte barr = src.Body; > } > > In this case, the session (retrieved from the helper class) was > connected and open, but I still received the error "session is not > connected". This makes me think that the src object is connected in > some way with the original session object, which has since been > disconnected. I was never sure what session the NHibernate API was > trying to use since the statement "src.Body" does not specify any > given session. So would it be true to state that the NHibernate API > links the session that was used to retrieve the "src" object with the > "src" object in some fashion? Otherwise, how would the API know > which session object to use in the src.Body call? > > Thoughts? > > - Peter > > -- > 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. > > -- 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.
