No. Hibernate Session object is not thread-safe, every thread should get its own session instance and close it after it’s work is finished. In other words, you cannot share it between threads.
Hibernate Session is a single-threaded, short-lived object conceptually modeling a "Unit of Work". In JPA nomenclature, the Session is represented by an EntityManager.
Behind the scenes, the Hibernate Session wraps a JDBC java.sql.Connection and acts as a factory for org.hibernate.Transaction instances. It maintains a generally "repeatable read" persistence context (first level cache) of the application domain model.
Check out Session object example at https://www.sourcecodeexamples.net/2019/11/hibernate-example-in-eclipse-using-maven.html.
Learn hibernate at https://www.javaguides.net/p/hibernate-tutorial.html.
Hibernate Framework
Hibernate Interview
Java
Comments
Post a Comment