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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T20:51:48+00:00 2026-05-10T20:51:48+00:00

I had a method with a lot of persistence calls that used a nHibernate

  • 0

I had a method with a lot of persistence calls that used a nHibernate session, it worked, was alright. But I needed to refactor this method, extracting a method from a content inside a loop, for multithread reasons. Then I created an class with this method. It is like a normal refactoring, but the nHibernate session inside this method call is broken, without context, I didn’t finalize it at any moment. Has nHibernate problems with multithreading? Even when I have only one more thread executing, I have the same problem.

I use nHibernate Session through a SessionFactory and Façade pattern, it means, the session is not a field of these objects, it is global at SessionFactory.


Making it a little bit more clear:

BEFORE:

Method() { ... persistence calls foreach(Thing..) { ...persistence calls for each thing (1) } ... } 

AFTER:

Method() { ... persistence calls foreach(Thing..) { create a thingResolver object with some data open a new thread with thingResolver.Method (1) starts this thread } .. waits for finishing threads and continues } 

Our nHibernate Session Factory is thread-aware, and stores/retrieves nHibernate session per thread. It is working nicely now 😉

  • 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. 2026-05-10T20:51:49+00:00Added an answer on May 10, 2026 at 8:51 pm

    Sessions are not thread safe in NHibernate by design. So it should be ok as long as you have a session used by only one thread.

    I’m not sure what you’re thingResolver does, but if it does some persistance calls on the same session you’ve created in the originating thread – this most probably the cause of your problems, you could create a separate session in your new thread so that it would be a session per thread if my assumption is true.

    NHibernate reference has it in section 10.2

    http://nhibernate.info/doc/nh/en/index.html#transactions

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

Sidebar

Ask A Question

Stats

  • Questions 69k
  • Answers 69k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer You could take a look at StringTemplate, which is a… May 11, 2026 at 12:46 pm
  • added an answer Issue happened because Linq Datacontext was created before transactionscope. Solution… May 11, 2026 at 12:46 pm
  • added an answer You have to make no front end changes to implement… May 11, 2026 at 12:46 pm

Related Questions

I was working on some code recently and came across a method that had
I'm a fan of extension methods in C#, but haven't had any success adding
I had a discussion with some colleagues mentioning that there are not too many
I had a plugin installed in Visual Studio 2008, and it created some extra
Here's a simplified version of what I'm trying to do : Before any other
Ok, so I had this neat little idea the other night to create a
I'm stuck with .Net 1.1 application (i.e. I can not use the generics goodies
I've had several clients ask this, and I've never been able to get or

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.