Introduction to HibernateUtil and the SessionFactory Interface

HibernateUtil is a convenience class for obtaining the Hibernate SessionFactory instance, which are used for building hibernate sessions. Hibernate sessions themselves are not thread safe i.e. there exists only one per thread of execution (used once and then discarded).

A typical HibernateUtil class looks like:

Some important points worth noting regarding the SessionFactory:

  • SessionFactory is an interface and extends Referenceable (interface with one method), Serializable (interface with no methods)
  • Used for building hibernate sessions. Threads servicing client requests obtain sessions from the factory.
  • Usually an application has a single SessionFactory.
  • SessionFactory is thread safe, and is created only once on server startup.
  • SessionFactory is immutable. The behaviour of a SessionFactory is controlled by properties supplied at configuration time.

Kindly put up all your queries as comment to this post.


Receive our updates to your inbox

Get more stuff like this
in your inbox

Subscribe to our mailing list and get interesting stuff and updates to your email inbox.