Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Configuration and SessionFactory  RSS feed

rakesh kadulkar
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I have a question regarding Configuration and SessionFactory classes which are important in launching hibernate.

It is said that Configuration class is essential in launching the hibernate. My question is launching the hibernate means what?

Further it seems that configuration class reads all the XML documents so the Configuration is a heavy weight component but even

then some book that I referred calls SessionFactory as a heavy weight component and therefore it should be created one per


Can some ine clarify me these thing.

Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
Hibernate Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your configuration object represents your initializations, and is an initialization time component:

"An instance of Configuration allows the application to specify properties and mapping documents to be used when creating a SessionFactory. Usually an application will create a single Configuration, build a single instance of SessionFactory and then instantiate Sessions in threads servicing client requests. The Configuration is meant only as an initialization-time object. SessionFactorys are immutable and do not retain any association back to the Configuration."

The SessionFactory uses the configuration object to create sessions, and sessions represent a period of interaction with the database where a transaction can be started and committed.

"Creates Sessions. Usually an application has a single SessionFactory. Threads servicing client requests obtain Sessions from the factory.

Implementors must be threadsafe.

SessionFactorys are immutable. The behaviour of a SessionFactory is controlled by properties supplied at configuration time. These properties are defined on Environment."

-Cameron McKenzie

It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!