This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Object Relational Mapping and the fly likes Configuration and SessionFactory Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Configuration and SessionFactory" Watch "Configuration and SessionFactory" New topic

Configuration and SessionFactory

rakesh kadulkar
Ranch Hand

Joined: Jul 24, 2008
Posts: 115

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.


Rakesh Kadulkar
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968

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

I agree. Here's the link:
subject: Configuration and SessionFactory
jQuery in Action, 3rd edition