aspose file tools*
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 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Databases » Object Relational Mapping
Bookmark "Configuration and SessionFactory" Watch "Configuration and SessionFactory" New topic
Author

Configuration and SessionFactory

rakesh kadulkar
Ranch Hand

Joined: Jul 24, 2008
Posts: 115
Hi,

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

application.

Can some ine clarify me these thing.

Thanks


Rakesh Kadulkar
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

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."
https://www.hibernate.org/hib_docs/v3/api/org/hibernate/cfg/Configuration.html

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."

https://www.hibernate.org/hib_docs/v3/api/org/hibernate/SessionFactory.html

-Cameron McKenzie

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Configuration and SessionFactory
 
Similar Threads
what is the difference ?
Regarding Session-Factory object
How internally works
SessionFactory returns same object everytime we call it?
only one SessionFactory Object per application right?