I am trying to understand the meaning of 'Hibernate session are not thread safe'. What I already know (please correct me if I am wrong):
- A session in non-JTA environment is saved in Thread Local. So it is bound to the current thread.
- Calling getCurrentSession() in a new thread will associate a new session with its own thread local.
- Suppose we share an entity between 2 threads (T1,T2), loaded in T1 and used in T2 we could have issues with lazy loading etc. because the sessions in T1 and T2 are different.
This explains what could go wrong when an entity is shared between different sessions.
What I fail to understand is the problems that could arise when a Session is shared between 2 or more threads. I know that methods in Session are not thread safe and can cause race conditions etc. but it is not clear how? I would greatly appreciate if someone could explain with example(s) or list down one or more scenarios to clarify.
Thanks in advance