nHibernate session and multithreading

前端 未结 2 2005
面向向阳花
面向向阳花 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:41

    You can have one NHibernate SessionFactory for multiple threads as long as you have a separate NHibernate session for each thread.

    here is an example that will give exceptions because it uses the same session for each thread:

    https://forum.hibernate.org/viewtopic.php?p=2373236&sid=db537baa5a57e3968abdda5cceec2a24

    The solution is to store sessions on the LocaldataStoreSlot, that way you can have a session-per-request model.

提交回复
热议问题