Hi all.
In short: The connection that is associated with the ISession object is open after calling transaction.Commit()
In not so short:
I use the trunk version of NHibernate.
My configuration file looks like this:
Code:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="hibernate-configuration" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate " />
</configSections>
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<session-factory>
<property name="connection.connection_string">Data Source=DBSOURCE;Initial Catalog=CATALOG;Persist Security Info=True;User ID=UID;Password=PWD</property>
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
<property name="dialect">NHibernate.Dialect.MsSql2000Dialect</property>
<property name="connection.release_mode">after_transaction</property>
</session-factory>
</hibernate-configuration>
</configuration>
Take note of the property: <property name="connection.release_mode">after_transaction</property> which should ensure that connections are released back to the connection pool after a transactional commit.
This is the test that fails:
Code:
[Test]
public void ISession_should_have_closed_connection_after_transaction_commit()
{
NHibernate.ISessionFactory _factory = new Configuration().AddAssembly("MyHbmFileMappingAssembly").BuildSessionFactory();
ISession session = _factory.OpenSession();
using (ITransaction tx = session.BeginTransaction())
{
IBlog blog = session.Get<Blog>(1);
tx.Commit();
}
Assert.That(session.IsConnected, Is.False, "Connection should be closed");
session.Close();
session = null;
}
with this message from NUnit:
Code:
MyAssembly.Tests.NHibernateSessionTest.ISession_should_have_closed_connection_after_transaction_commit:
Connection should be closed
Expected: False
But was: True
According to the v1.2.0 documentation (10.7. Connection Release Modes) I should expect the connection to be closed after committing the transaction. But it seems that the connection is kept alive and open as long as the associated ISession is alive.
Any ideas or suggestions on this? Am I misunderstanding something vital here?