nHibernate session and multithreading

前端 未结 2 2006
面向向阳花
面向向阳花 2020-12-10 04:29

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 conte

2条回答
  •  春和景丽
    2020-12-10 04:32

    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

提交回复
热议问题