These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 
Author Message
 Post subject: Connection not closed after transaction commit
PostPosted: Wed Nov 05, 2008 9:25 am 
Newbie

Joined: Wed Nov 05, 2008 6:54 am
Posts: 3
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?


Top
 Profile  
 
 Post subject: Re: Connection not closed after transaction commit
PostPosted: Fri Nov 07, 2008 9:20 am 
Newbie

Joined: Thu May 15, 2008 4:09 am
Posts: 1
Yes, you're correct. In my little knowledge with NHibernate code that does closing the connection after tx.Commit() calls an internal method CloseIfRequired but that does nothing in this case. I am sure something is misbehaving here. May be some one from dev can help.

Code:
      void CloseIfRequerid()
      {
         //bool close = session.ShouldAutoClose() && !transactionContext.isClosed();
         //if (close)
         //{
         //    transactionContext.managedClose();
         //}
      }


Thanks,
Vadi


Top
 Profile  
 
 Post subject: Re: Connection not closed after transaction commit
PostPosted: Sat Nov 08, 2008 7:46 am 
Newbie

Joined: Wed Nov 05, 2008 6:54 am
Posts: 3
Thanks Vadi - I tried debugging my way through the call and ended up the same place as you show.

For now I'll work my way around it and when (if) I get the time, I'll try to make a patch for this misbehaving feature... :)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Nov 10, 2008 1:43 pm 
Newbie

Joined: Thu Dec 21, 2006 4:34 am
Posts: 13
There is no need for a patch!

This issue has been discussed here: http://groups.google.com/group/nhusers/ ... c78c2b3dc4

Christian


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 12, 2008 3:20 am 
Newbie

Joined: Wed Nov 05, 2008 6:54 am
Posts: 3
christianacca wrote:
There is no need for a patch!

This issue has been discussed here: http://groups.google.com/group/nhusers/ ... c78c2b3dc4

Christian

Indeed! Thank you Christian!


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.