0

I've got an ASP MVC application where I am editing a field and posting the change back via Javascript like so:

    "saveAndClose": function () {
    var url = baseURL + "Product/UpdateProductFamily/" + $.trim($('#Id').text()) + "/" + $('#recordValue').val();
    $.get(
    url,
    function (returnedData) {
        alert('worked');
    });

The call doesn't even make it to the controller, instead I get an exception in the NHibernate Session manager:

        private static void BeginTransaction(object sender, EventArgs e)
    {
        var x = NHibernateSessionManager.Instance;
        x.BeginTransaction();

        Thread.CurrentThread.Name = x.GetSession().GetSessionImplementation().SessionId.ToString(); 

    }

The x.GetSession() line errors saying "The property is already set and cannot be modified".

What's going on here? Why is a simple JQuery get to the controller causing this NHibernate error?

2
  • I might be misunderstanding what you are trying to do - but if you're doing a save shouldn't you be doing a post rather than a get? Also have you tried outputting what the 'url' value is to see if it looks like a valid route? Commented Aug 24, 2011 at 4:19
  • Good questions Jen, I checked the url value and it is absolutely valid route. As far as the Get, seems like a much lighter way to save the data (I'm passing the two values to save in the URL) versus creating a form and doing a Post. Commented Aug 24, 2011 at 4:31

1 Answer 1

1

The error you are getting is the result of trying to set the Name of the CurrentThread after it has been set.

http://msdn.microsoft.com/en-us/library/system.threading.thread.name.aspx

What I am not sure of, is why you need to set the name of the thread to the current session id.

Sign up to request clarification or add additional context in comments.

4 Comments

Thanks a bunch :). That's there so logging can associate session (and associated SQL Statements). My question is more around WHY the code is even being called before my controller is even hit.
You would need show the stack trace for the InvalidOperationException to determine how the BeginTransaction method is begin called. Many people implement a transaction-per-request when using NHibernate in ASP.NET MVC. It could be that BeginTransaction is being called whenever a new request is made or by an ActionFilterAttribute applied to the controller/action.
Yup, I think that's what's going on
The call was unnecessary, when consulting with the guy who put that in they confirmed that it could be removed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.