Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Differences between session vs session factory - Hibernate?

Do we have any other differences other than the below? Also please validate whether the below are correct

  1. SessionFactory objects are one per application and Session objects are one per client.
  2. SessionFactory is to create and manage Sessions. Session is to provide a CRUD interface for mapped classes, and also access to the more versatile Criteria API.
  3. SessionFactory is thread safe where as Session is not thread safe
like image 654
user2323036 Avatar asked Mar 18 '14 05:03

user2323036


2 Answers

First of all, asking the difference between these interfaces doesn't make any sense. It seems like asking the difference between car manufacturing plant and car. A manufacturing plant is a place where the cars will be produced. Similarly, SessionFactory is an instance which will create Session objects.

like image 187
Balaji Reddy Avatar answered Sep 18 '22 10:09

Balaji Reddy


SessionFactory is a factory class for Session objects. It is available for the whole application while a Session is only available for particular transaction.

Session is short-lived while SessionFactory objects are long-lived. SessionFactory provides a second level cache and Session provides a first level cache.

like image 39
abhay singh Avatar answered Sep 19 '22 10:09

abhay singh