What is the role of Session object in Hibernate?

Answered

What is the role of Session object in Hibernate?Is it thread-safe?

Ninja Asked on 17th September 2018 in Hibernate.
Add Comment
1 Answer(s)
Best answer

Session object represents a unit of work in Hibernate that represents conversation between application and database. It is used to maintain connection with database. Session object is referred to as persistence manager since it is responsible for storing and retrieving object to and from database.

Session object is single threaded and hence it is not thread-safe. It can’t be shared between multiple threads.

Session object is created with the SessionFactory object:

SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
Session session = sessionFactory.openSession();

Ninja Answered on 17th September 2018.
Add Comment