I use Spring.NET AOP for transaction and session management with NHibernate. When user makes several requests too quick - lazy loading is failed with exception "no session or session was closed".
I use SpringSessionContext as CurrentSessionContext in NHibernate configuration
and OpenSessionInView moduleCode:public class FluentSessionFactory : LocalSessionFactoryObject { protected override ISessionFactory NewSessionFactory(Configuration config) { var conf = Fluently .Configure() .Database( MsSqlConfiguration .MsSql2008 .ConnectionString(c => c.FromConnectionStringWithKey("MyConnection")) // TODO: use ExposeConfiguration method .CurrentSessionContext<SpringSessionContext>() ) .Mappings( m => m.FluentMappings .AddFromAssembly(this.GetType().Assembly) ) .BuildSessionFactory(); return conf; } }
Application implements next workflow for getting entities from db: View -> Controller -> Manager -> Repository and same to other side. So session is created per request, transaction - per call to manager.Code:<system.webServer> <validation validateIntegratedModeConfiguration="false"/> <modules runAllManagedModulesForAllRequests="true"> <add name="OpenSessionInView" type="Spring.Data.NHibernate.Support.OpenSessionInViewModule, Spring.Data.NHibernate31"/> </modules> </system.webServer>
What are possible reasons of such behaviour and how can I solve this problem(Not.LazyLoad() and NHibernateUtil.Initialize() are not acceptable variants in my context)?Code:<object id="TransactionManager" type="Spring.Data.NHibernate.HibernateTransactionManager, Spring.Data.NHibernate31"> <property name="DbProvider" ref="DbProvider"/> <property name="SessionFactory" ref="SessionFactory"/> </object> <tx:advice id="TxAdvice" transaction-manager="TransactionManager"> <tx:attributes> <tx:method name="*"/> </tx:attributes> </tx:advice> <object id="Pointcut" type="Spring.Aop.Support.SdkRegularExpressionMethodPointcut, Spring.Aop"> <property name="patterns"> <list> <value>MyAppication.Managers.AccountManager</value> <value>MyAppication.Managers.CompanyManager</value> </list> </property> </object> <aop:config> <aop:advisor advice-ref="TxAdvice" pointcut-ref="Pointcut"/> </aop:config>


Reply With Quote
