title: NHibernate + Spring.NET lazy loading failed - no session
body: <p>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". </p>
  
  <p>I use SpringSessionContext as CurrentSessionContext in NHibernate configuration </p>
  
  <pre><code>public class FluentSessionFactory : LocalSessionFactoryObject
  {
      protected override ISessionFactory NewSessionFactory(Configuration config)
      {
          var conf = Fluently
              .Configure()
              .Database(
                  MsSqlConfiguration
                      .MsSql2008
                      .ConnectionString(c =&gt; c.FromConnectionStringWithKey("MyConnection"))
                      // TODO: use ExposeConfiguration method
                      .CurrentSessionContext&lt;SpringSessionContext&gt;()
                  )
              .Mappings(
                  m =&gt; m.FluentMappings
                      .AddFromAssembly(this.GetType().Assembly)
              )
              .BuildSessionFactory();
          return conf;
      }
  }
  </code></pre>
  
  <p>In xml config:</p>
  
  <pre><code>&lt;object id="SessionFactory" type="IndustryTracker.NHibernateRepository.FluentSessionFactory, IndustryTracker.NHibernateRepository"&gt;
      &lt;property name="DbProvider" ref="DbProvider" /&gt;
  &lt;/object&gt;
  </code></pre>
  
  <p>and OpenSessionInView module</p>
  
  <pre><code>&lt;system.webServer&gt;
      &lt;validation validateIntegratedModeConfiguration="false"/&gt;
      &lt;modules runAllManagedModulesForAllRequests="true"&gt;
          &lt;add name="OpenSessionInView"  type="Spring.Data.NHibernate.Support.OpenSessionInViewModule, Spring.Data.NHibernate31"/&gt;
      &lt;/modules&gt;
  &lt;/system.webServer&gt;
  </code></pre>
  
  <p>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.</p>
  
  <pre><code>&lt;object id="TransactionManager" type="Spring.Data.NHibernate.HibernateTransactionManager, Spring.Data.NHibernate31"&gt;
      &lt;property name="DbProvider" ref="DbProvider"/&gt;
      &lt;property name="SessionFactory" ref="SessionFactory"/&gt;
  &lt;/object&gt;
  
  &lt;tx:advice id="TxAdvice" transaction-manager="TransactionManager"&gt;
      &lt;tx:attributes&gt;
          &lt;tx:method name="*"/&gt;
      &lt;/tx:attributes&gt;
  &lt;/tx:advice&gt;
  
  &lt;object id="Pointcut" type="Spring.Aop.Support.SdkRegularExpressionMethodPointcut, Spring.Aop"&gt;
      &lt;property name="patterns"&gt;
          &lt;list&gt;
              &lt;value&gt;MyAppication.Managers.AccountManager&lt;/value&gt;
              &lt;value&gt;MyAppication.Managers.CompanyManager&lt;/value&gt;
          &lt;/list&gt;
      &lt;/property&gt;
  &lt;/object&gt;
  
  &lt;aop:config&gt;
      &lt;aop:advisor advice-ref="TxAdvice" pointcut-ref="Pointcut"/&gt;
  &lt;/aop:config&gt;
  </code></pre>
  
  <p>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)?</p>