Nhibernate + Spring.Net + Transaction + too many threads
I am using Sping.Net 1.3.1 and Nhibernate 3.0. I use Spring's Transaction Interceptor in order to create my Transactions. I mark my Transactional methods with the Transaction Attribute. My server gets something like 20 - 25 requests per second, each request is handled on a new thread, using parallel's Task. I run a stress test in order to verify my server capability of handling the calls. when i run only two or three calls ion a time, every thing works great, but when I run 5 -10 calls simultanly I got an exception from Spring.
The exception is:
Spring.Transaction.TransactionSystemException was unhandled by user code
Message=Could not commit Hibernate transaction
Source=Spring.Data.NHibernate30
StackTrace:
at Spring.Data.NHibernate.HibernateTransactionManager.DoCommit(DefaultTransactionStatus status) in c:\_svn\spring-net\tags\spring-net-1.3.1\src\Spring\Spring.Data.NHibernate\Data\NHibernate\HibernateTransactionManager.cs:line 568
at Spring.Transaction.Support.AbstractPlatformTransactionManager.ProcessCommit(DefaultTransactionStatus status)
InnerException: NHibernate.TransactionException
Message=Transaction not connected, or was disconnected
Source=NHibernate
StackTrace:
at NHibernate.Transaction.AdoT开发者_如何学运维ransaction.CheckNotZombied() in d:\CSharp\NH\nhibernate\src\NHibernate\Transaction\AdoTransaction.cs:line 408
at NHibernate.Transaction.AdoTransaction.Commit() in d:\CSharp\NH\nhibernate\src\NHibernate\Transaction\AdoTransaction.cs:line 181
at Spring.Data.NHibernate.HibernateTransactionManager.DoCommit(DefaultTransactionStatus status) in c:\_svn\spring-net\tags\spring-net-1.3.1\src\Spring\Spring.Data.NHibernate\Data\NHibernate\HibernateTransactionManager.cs:line 556
InnerException:
Thank you very much, Or Chubook.
I am sure you have already discovered this answer by now. When you share a NHibernate session among multiple threads, you will run into this concurrency problem. Each thread must have their own session in scope in order to avoid a transaction disconnect state.
精彩评论