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 8938065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:32:20+00:00 2026-06-15T10:32:20+00:00

My ASP.NET MVC 4 project is using NHibernate (behind repositories) and Castle Windsor, using

  • 0

My ASP.NET MVC 4 project is using NHibernate (behind repositories) and Castle Windsor, using the AutoTx and NHibernate Facilities. I’ve followed the guide written by haf and my I can create and read objects.

My PersistenceInstaller looks like this

public class PersistenceInstaller : IWindsorInstaller
{
    public void Install(Castle.Windsor.IWindsorContainer container, Castle.MicroKernel.SubSystems.Configuration.IConfigurationStore store)
    {
        container.AddFacility<AutoTxFacility>();            
        container.Register(Component.For<INHibernateInstaller>().ImplementedBy<NHibernateInstaller>().LifeStyle.Singleton);
        container.AddFacility<NHibernateFacility>(
            f => f.DefaultLifeStyle = DefaultSessionLifeStyleOption.SessionPerWebRequest);          
    }
}

The NHibernateInstaller is straight from the NHib Facility Quickstart.

I am using ISessionManager in my base repository…

protected ISession Session
{
    get
    {
        return _sessionManager.OpenSession();
    }
}

public virtual T Commit(T entity)
{
    Session.SaveOrUpdate(entity);            
    return entity;
}

Finally, my application code which is causing the problem:

[HttpPost]
[ValidateAntiForgeryToken]        
[Transaction]
public ActionResult Maintain(PrescriberMaintainViewModel viewModel)
{           
    if (ModelState.IsValid)
    {
        var prescriber = UserRepository.GetPrescriber(User.Identity.Name);

        //var prescriber = new Prescriber { DateJoined = DateTime.Today, Username = "Test" };                
        prescriber.SecurityQuestion = viewModel.SecurityQuestion;
        prescriber.SecurityAnswer = viewModel.SecurityAnswer;
        prescriber.EmailAddress = viewModel.Email;
        prescriber.FirstName = viewModel.FirstName;
        prescriber.LastName = viewModel.LastName;
        prescriber.Address = new Address
                                {
                                    Address1 = viewModel.AddressLine1,
                                    Address2 = viewModel.AddressLine2,
                                    Address3 = viewModel.AddressLine3,
                                    Suburb = viewModel.Suburb,
                                    State = viewModel.State,
                                    Postcode = viewModel.Postcode,
                                    Country = string.Empty
                                };

        prescriber.MobileNumber = viewModel.MobileNumber;
        prescriber.PhoneNumber = viewModel.PhoneNumber;
        prescriber.DateOfBirth = viewModel.DateOfBirth;
        prescriber.AHPRANumber = viewModel.AhpraNumber;
        prescriber.ClinicName = viewModel.ClinicName;
        prescriber.ClinicWebUrl = viewModel.ClinicWebUrl;
        prescriber.Qualifications = viewModel.Qualifications;
        prescriber.JobTitle = viewModel.JobTitle;


        UserRepository.Commit(prescriber);          
    }

    return View(viewModel);
}

The above code will save a new prescriber (tested by uncommenting out the commented out line etc).

I am using NHProf and have confirmed that no sql is sent to the database for the Update. I can see the read being performed but that’s it.

It seems to me that NHibernate doesn’t recognise the entity as being changed and therefore does not generate the sql. Or possibly the transaction isn’t being committed?

I’ve been scouring the webs for a few hours now trying to work this one out and as a last act of desperation have posted on SO. Any ideas? 🙂

Oh and in NHProf I see three Sessions (1 for the GetPrescriber call from the repo, one I assume for the update (with no sql) – and one for some action in my actionfilter on the base class). I also get an alert about the use of implicit transactions. This confuses me because I thought I was doing everything I needed to get an transaction – using AutoTx and the Transaction attribute. I also expected there to be only 1 session per webrequest, as per my Windsor config.

UPDATE: It seems, after spending the day reading through the source for NHibernateFacility and AutoTx Facility for automatic transactions, that AutoTx is not setting the Interceptors on my implementation of INHibernateInstaller. It seems this means whenever SessionManager calls OpenSession it is calling the default version with no parameter, rather than the one that accepts an Interceptor. Internally AutoTxFacility registers TransactionInterceptor with windsor, so that it can be added the Interceptor on my INHibernateInstaller concrete, by windsor making use of the AutoTx’s TransactionalComponentInspector

AutoTxFacility source on github

  • 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-15T10:32:21+00:00Added an answer on June 15, 2026 at 10:32 am

    After spending a full day yesterday searching through the AutoTx and NHibernate facilities on github and getting nowhere, I started a clean project in an attempt to replicate the problem. Unfortunately for the replication, everything worked! I ran Update-Package on my source and brought down new version of Castle.Transactions and I was running correctly. I did make a small adjustment to my own code. That was to remove the UserRepository.Commit line.

    I did not need to modify how I opened sessions. That was taken care of by the SessionManager instance. With the update to Castle.Transactions, the Transaction attribute is being recognised and a transaction is being created (as evidenced by no more alert in NHProf).

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

Sidebar

Related Questions

I am using AutoMapper in my project along with, NHibernate and ASP.NET MVC 2.
I'm currently working on an ASP.NET MVC project using NHibernate and I need to
I'm about to kick off a new project using NHibernate and ASP.Net MVC and
I'm starting an ASP.NET MVC project using SubSonic 3 ActiveRecord. I added a table
This is my model of my asp.net mvc 2 project : using System; using
I'm working with an ASP.NET MVC 2 project using a classic ASP.NET WebForm wired
I am using knockout.js in my ASP.NET MVC project. I figured out how to
I'm using ELMAH to handle the exceptions in my ASP.Net MVC project. I would
In a ASP.NET MVC (Razor) project, I'm using a ListBox with Multi Select option
I'm using the ImageResizer module in an ASP.NET MVC 4 project, along with the

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.