Is Hibernate's session thread safe?

后端 未结 5 894
名媛妹妹
名媛妹妹 2020-12-06 00:01

I need to know, whether the Hibernate\'s session is thread safe or not. But obvious a new session is attached to every thread for execution. But my question is if in one thr

5条回答
  •  鱼传尺愫
    2020-12-06 00:45

    Hibernate session and threads do not mix.

    You should not use a session from multiple threads at once, and I recommend you only use a session from a single thread. DB session implementations are not even required to be theadsafe.

    You also must consider what happens to the transactions when you start doing things in multiple threads. Transactions are tied to the current thread. This becomes quickly mindblowing and you enter areas where the implementers have not tested their products.

    In the end life is too short to get lost in that swamp.

提交回复
热议问题