Differences between session vs session factory - Hibernate?

user2323036 picture user2323036 · Mar 18, 2014 · Viewed 61k times · Source

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

Answer

Balaji Reddy picture Balaji Reddy · Mar 18, 2014

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.