Differences between session vs session factory - Hibernate?
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.
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.