NHibernate transactions randomly not rolled back

Posted by cbp on Stack Overflow See other posts from Stack Overflow or by cbp
Published on 2009-10-14T03:24:34Z Indexed on 2010/03/30 8:43 UTC
Read the original article Hit count: 415

Filed under:
|

I have a suite of integration tests that run inside transactions. Sometimes it seems that NHibernate transactions are not being correctly rolled back. I can't work out what causes this.

Here is a slightly simplified overview of the base class that these integration test fixtures run with:

public class IntegrationTestFixture
{
    private TransactionScope _transactionScope;
    private ConnectionScope _connectionScope;

    [TestFixtureSetUp]
    public virtual void TestFixtureSetUp()
    {
        var session = NHibernateSessionManager.SessionFactory.OpenSession();
        CallSessionContext.Bind(session);
        _connectionScope = new ConnectionScope();
        _transactionScope = new TransactionScope();
    }

    [TestFixtureTearDown]
    public virtual void TestFixtureTearDown()
    {
        _transactionScope.Dispose();
        _connectionScope.Dispose();
        var session = CurrentSessionContext.Unbind(SessionFactory);
        session.Close();
        session.Dispose();
    }
}

A call to the TransactionScope's commit method is never made, therefore how is it possible that data still ends up in the database?

© Stack Overflow or respective owner

Related posts about nhibernate

Related posts about transaction