Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Configuration and SessionFactory

 
rakesh kadulkar
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper
Posts: 4968
1
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."
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

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic