diff --git a/src/NHibernate.Test/NHSpecificTest/NH3985/Entity.cs b/src/NHibernate.Test/NHSpecificTest/NH3985/Entity.cs new file mode 100644 index 00000000000..eea82a152ce --- /dev/null +++ b/src/NHibernate.Test/NHSpecificTest/NH3985/Entity.cs @@ -0,0 +1,10 @@ +using System; + +namespace NHibernate.Test.NHSpecificTest.NH3985 +{ + public partial class Process + { + public virtual Guid ProcessID { get; set; } + public virtual string Name { get; set; } + } +} diff --git a/src/NHibernate.Test/NHSpecificTest/NH3985/Fixture.cs b/src/NHibernate.Test/NHSpecificTest/NH3985/Fixture.cs new file mode 100644 index 00000000000..b08e0fc8827 --- /dev/null +++ b/src/NHibernate.Test/NHSpecificTest/NH3985/Fixture.cs @@ -0,0 +1,43 @@ +using NUnit.Framework; +using System; + +namespace NHibernate.Test.NHSpecificTest.NH3985 +{ + /// + /// The test verifies that subsequent child sessions are not issued in already-disposed state. + /// + [TestFixture] + public class Fixture : BugTestCase + { + [Test] + public void GetChildSession_ShouldReturnNonDisposedInstance() + { + using (var rootSession = OpenSession()) + { + using (var childSession1 = rootSession.GetChildSession()) + { + } + + using (var childSession2 = rootSession.GetChildSession()) + { + Assert.DoesNotThrow(() => { childSession2.Get(Guid.NewGuid()); }); + } + } + } + + [Test] + public void GetChildSession_ShouldReturnNonClosedInstance() + { + using (var rootSession = OpenSession()) + { + var childSession1 = rootSession.GetChildSession(); + childSession1.Close(); + + using (var childSession2 = rootSession.GetChildSession()) + { + Assert.DoesNotThrow(() => { childSession2.Get(Guid.NewGuid()); }); + } + } + } + } +} diff --git a/src/NHibernate.Test/NHSpecificTest/NH3985/Mappings.hbm.xml b/src/NHibernate.Test/NHSpecificTest/NH3985/Mappings.hbm.xml new file mode 100644 index 00000000000..d6631f360db --- /dev/null +++ b/src/NHibernate.Test/NHSpecificTest/NH3985/Mappings.hbm.xml @@ -0,0 +1,7 @@ + + + + + + + diff --git a/src/NHibernate.Test/NHibernate.Test.csproj b/src/NHibernate.Test/NHibernate.Test.csproj index 152ab1994a6..687a66d2b41 100644 --- a/src/NHibernate.Test/NHibernate.Test.csproj +++ b/src/NHibernate.Test/NHibernate.Test.csproj @@ -743,6 +743,8 @@ + + @@ -2668,6 +2670,7 @@ + diff --git a/src/NHibernate/Impl/SessionImpl.cs b/src/NHibernate/Impl/SessionImpl.cs index 27a127fd3e1..fd6ba98b5f0 100644 --- a/src/NHibernate/Impl/SessionImpl.cs +++ b/src/NHibernate/Impl/SessionImpl.cs @@ -73,7 +73,7 @@ public sealed class SessionImpl : AbstractSessionImpl, IEventSource, ISerializab private readonly StatefulPersistenceContext persistenceContext; [NonSerialized] - private readonly ISession rootSession; + private readonly SessionImpl rootSession; [NonSerialized] ISession _childSession; @@ -381,6 +381,7 @@ public DbConnection Close() { SetClosed(); Cleanup(); + if (rootSession != null) rootSession._childSession = null; } } } @@ -1681,6 +1682,7 @@ private void Dispose(bool isDisposing) // free unmanaged resources here IsAlreadyDisposed = true; + // nothing for Finalizer to do - so tell the GC to ignore it GC.SuppressFinalize(this); }