Created
August 8, 2013 08:54
-
-
Save andreasohlund/6182903 to your computer and use it in GitHub Desktop.
NH bug workaround
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void IManageUnitsOfWork.End(Exception ex) | |
| { | |
| if (SessionFactory == null || currentSession == null) return; | |
| if (ex != null) | |
| { | |
| Transaction.Current.Rollback(ex); | |
| while (Transaction.Current.TransactionInformation.Status != TransactionStatus.Aborted) | |
| { | |
| Thread.SpinWait(20); | |
| } | |
| } | |
| using (currentSession) | |
| using (currentSession.Transaction) | |
| { | |
| if (!currentSession.Transaction.IsActive) | |
| return; | |
| if (ex != null) | |
| { | |
| // Due to a race condition in NH3.3, explicit rollback can cause exceptions and corrupt the connection pool. | |
| // Especially if there are more than one NH session taking part in the DTC transaction | |
| currentSession.Transaction.Rollback(); | |
| } | |
| else | |
| currentSession.Transaction.Commit(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment