Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using DependentTransaction fails #2172

Closed
guoleilove33 opened this issue Jun 11, 2019 · 2 comments
Closed

Using DependentTransaction fails #2172

guoleilove33 opened this issue Jun 11, 2019 · 2 comments

Comments

@guoleilove33
Copy link

guoleilove33 commented Jun 11, 2019

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);
            }
        }
    }
fredericDelaporte added a commit to fredericDelaporte/nhibernate-core that referenced this issue Aug 24, 2019
@fredericDelaporte fredericDelaporte changed the title Something went wrong when using DependentTransaction Using DependentTransaction fails Aug 24, 2019
@fredericDelaporte fredericDelaporte added this to the 5.2.6 milestone Aug 24, 2019
fredericDelaporte added a commit to fredericDelaporte/nhibernate-core that referenced this issue Aug 24, 2019
fredericDelaporte added a commit to fredericDelaporte/nhibernate-core that referenced this issue Aug 24, 2019
fredericDelaporte added a commit to fredericDelaporte/nhibernate-core that referenced this issue Aug 24, 2019
@fredericDelaporte
Copy link
Member

fredericDelaporte commented Aug 25, 2019

There is some ongoing work to support dependent transaction in NH 5.x, currently targeted to 5.2.x but which may be back-ported down to 5.0.x. See #2197.

Since this regression is two years old and is only reported now, it seems using dependent transaction is not very common place. And we were indeed not having any test on them. Just fixing the test case you provide here may not be enough to fix it entirely.

To avoid a multi-releases fix process, may you please test the binaries from the PR builds with your real case application? In the PR's builds list, you can go to the details of "NHibernate (Release Package)" build, login into TeamCity (anonymous logon available), and retrieves build artifacts (including a NuGet package) from the artifacts tab.

fredericDelaporte added a commit to fredericDelaporte/nhibernate-core that referenced this issue Sep 8, 2019
fredericDelaporte added a commit to fredericDelaporte/nhibernate-core that referenced this issue Sep 8, 2019
@guoleilove33
Copy link
Author

Ok ,thanks very much

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants