Skip to content

Using DependentTransaction fails #2172

Closed
@guoleilove33

Description

@guoleilove33

When I use Transaction.Current.DependentClone(DependentCloneOption.RollbackIfNotComplete), Nhibernate went wrong. The error message is HibernateException: Synchronization timeout for transaction completion. Either raise {Cfg.Environment.SystemTransactionCompletionLockTimeout}, or this may be a bug in NHibernate.. This error may occur in NHibernate 5.x.x
Here is the code:

    public class TestNHibernate
    {
        public static void Main(string[] arg)
        {
            new TestNHibernate().Do1();
        }
        public virtual void Do1()
        {
            Transaction.Current = new CommittableTransaction();
            var current = Transaction.Current;
            Do2();
            (current as CommittableTransaction)?.Commit();
        }
        public virtual void Do2()
        {
            var current1 = Transaction.Current;
            Transaction.Current = Transaction.Current.DependentClone(DependentCloneOption.RollbackIfNotComplete);
            var builtSessionFactory =
                Fluently.Configure()
                    .Database(
                        MsSqlConfiguration.MsSql2012.ConnectionString(
                            @"Server=localhost;Database=test;user=sa;password=123;Trusted_Connection=True;"))
                    .Mappings(m => m.FluentMappings.Add<PM>())
                    .BuildSessionFactory();
            var session = builtSessionFactory.OpenSession();
            session.Save(new Person { });
            (Transaction.Current as DependentTransaction).Complete();
            Transaction.Current.Dispose();
            Transaction.Current = current1;
        }
        public class Person
        {
            public virtual int Id { get; set; }
            public virtual string Name { get; set; }
        }
        public class PM : ClassMap<Person>
        {
            public PM()
            {
                Id(person => person.Id);
                Map(u => u.Name);
            }
        }
    }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions