Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8061989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:30:58+00:00 2026-06-05T10:30:58+00:00

I use Spring.NET AOP for transaction and session management with NHibernate. When user makes

  • 0

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

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;
    }
}

In xml config:

<object id="SessionFactory" type="IndustryTracker.NHibernateRepository.FluentSessionFactory, IndustryTracker.NHibernateRepository">
    <property name="DbProvider" ref="DbProvider" />
</object>

and OpenSessionInView module

<system.webServer>
    <validation validateIntegratedModeConfiguration="false"/>
    <modules runAllManagedModulesForAllRequests="true">
        <add name="OpenSessionInView"  type="Spring.Data.NHibernate.Support.OpenSessionInViewModule, Spring.Data.NHibernate31"/>
    </modules>
</system.webServer>

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.

<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>

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)?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T10:30:59+00:00Added an answer on June 5, 2026 at 10:30 am

    1. Session factory configured for OpenSessionInViewModule?

    You might have forgotten to configure the session factory for the OpenSessionInViewModule:

    <appSettings>
      <add key="Spring.Data.NHibernate.Support.OpenSessionInViewModule.SessionFactoryObjectName" 
           value="SessionFactory"/>
    </appSettings>
    

    This has to be done in the app settings.

    2. Correct FluentNHibernate based spring session factory?

    You seem to be configuring your session factory in code. Have you tried configuring the session factory like described in the docs and on BennyM ‘s blog? Your NewSessionFactory method returns a session factory from straight from Fluent NHibernate, bypassing all spring.net support.

    3. Is your session factory transaction aware?

    <object id="SessionFactory" 
            type="IndustryTracker.NHibernateRepository.FluentSessionFactory, IndustryTracker.NHibernateRepository">
      <property name="DbProvider" ref="DbProvider" />
      <!-- provides integation with Spring's declarative transaction management features -->
      <property name="ExposeTransactionAwareSessionFactory" value="true" /> 
    </object>
    

    4. Does your controller have dependencies with scope="application" or no scope definition?

    I might have been looking in the wrong direction here. If your controller has dependencies of application scope, it would mean that quick requests could interfere. The default is "scope="application"; so you’d want to check collaborators without scope definitions too. See the docs on web scopes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using Sping.Net 1.3.1 and Nhibernate 3.0. I use Spring's Transaction Interceptor in
We are using Spring.NET for Dependency Injection and NHibernate as ORM. We use Session
I would like use Spring.NET for IoC , DI, AOP and Caliburn as MVVVM
I'm working on a demo that makes use of Spring.NET IoC capability in ASP.NET
I am trying to use Spring.NET with a C# application to populate a parameter
i am using Spring.net 1.2 with NHibernate 2.0.1. Within my project i'am facing some
I'm using Spring.NET 1.3.2, NHibernate 3.1 and the OSIV pattern in a ASP.NET application.
this is my first and also I am beginner in Spring.NET and also AOP.
I've been using the Spring.Net IoC container and can use it to inject properties
How can I setup NHibernate Validator with Spring.net as IoC? I am already using

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.