From 082ee5d0d07890093532bbfba46a4db50dd3c38c Mon Sep 17 00:00:00 2001 From: Yerko Nauls Date: Mon, 16 Mar 2015 22:32:02 -0400 Subject: [PATCH] Modified IsExistingTransaction, included uncommented code to check for transactions hibernateTransactionObject.HasTransaction() to check that Transaction.Current is not null and that the HibernateTransactionObject has a transaction too. Un-commenting this will by pass HandleExistingTransaction() on the second service call, Unit Test ->ServiceMethodWithNotSupported1 -> ServiceMethodWithNotSupported2, Forcing to create an "empty transaction" for the ServiceMethodWithNotSupported2 call. This seems to make sense since The the call to ServiceMethodWithNotSupported1 suspended the existing transaction, by the call to ServiceMethodWithNotSupported2, there is no transaction to suspend. Please advice on this potential solution. --- .../HibernateTxScopeTransactionManager.cs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/Spring/Spring.Data.NHibernate/Data/NHibernate/HibernateTxScopeTransactionManager.cs b/src/Spring/Spring.Data.NHibernate/Data/NHibernate/HibernateTxScopeTransactionManager.cs index 9342eee6..fa51c74e 100644 --- a/src/Spring/Spring.Data.NHibernate/Data/NHibernate/HibernateTxScopeTransactionManager.cs +++ b/src/Spring/Spring.Data.NHibernate/Data/NHibernate/HibernateTxScopeTransactionManager.cs @@ -342,10 +342,12 @@ namespace Spring.Data.NHibernate /// protected override bool IsExistingTransaction(object transaction) { - return - ((HibernateTransactionObject)transaction).PromotableTxScopeTransactionObject.TxScopeAdapter. - IsExistingTransaction; - //return ((HibernateTransactionObject) transaction).HasTransaction(); + var hibernateTransactionObject = ((HibernateTransactionObject) transaction); + + var hasExistingPromotableTxScopeTransaction = hibernateTransactionObject.PromotableTxScopeTransactionObject.TxScopeAdapter.IsExistingTransaction; + var hasExistingTransaction = hibernateTransactionObject.HasTransaction(); + + return hasExistingPromotableTxScopeTransaction && hasExistingTransaction; } /// @@ -951,12 +953,14 @@ namespace Spring.Data.NHibernate } */ ISession session = txObject.SessionHolder.Session; + if (txObject.NewSessionHolder) { if (log.IsDebugEnabled) { log.Debug("Closing Hibernate Session [" + session + "] after transaction"); } + SessionFactoryUtils.CloseSessionOrRegisterDeferredClose(session, SessionFactory); } else @@ -970,9 +974,8 @@ namespace Spring.Data.NHibernate session.FlushMode = txObject.SessionHolder.PreviousFlushMode; } } + txObject.SessionHolder.Clear(); - - } private class HibernateTransactionObject : AdoTransactionObjectSupport