Is the Session threadsafe in Hibernate ?
-
a) TRUE
-
b) FALSE
-
c) no matter
-
d) none of the above
B
Correct answer
Explanation
In Hibernate, the Session object is explicitly NOT thread-safe and is designed for use by a single thread at a time. Hibernate's documentation states that sharing a Session across threads without synchronization can cause unpredictable behavior. For concurrent access, you should use separate Session instances per thread or consider using Hibernate's SessionFactory with proper isolation. Each thread should obtain its own Session from the SessionFactory.