Session is not thread-safe
When using hibernate to develop DAO module, we have the most dealings with the session, so how to manage the session reasonably and avoid the frequent creation and destruction of the session is very important for improving the performance of the system. It used to be done automatically through the Eclipse plug-in to automate the code, but the effect was good, but always uncomfortable (not reading the lengthy code), so now you're going to implement the session Management code yourself. We know that the session is created by Sessionfactory, and the implementation of Sessionfactory is thread-safe, and multiple concurrent threads can access a sessionfactory and get a session instance from it. So is the session thread-safe? Unfortunately, the answer is no. The session contains state information related to database operations, so if multiple threads are using a session instance for CRUD at the same time, it is likely to cause confusion in data access, can you imagine that you simply cannot predict the execution sequence of the thread of your record to operate the situation?
Session is not thread-safe