Configuration or AnnotationConfiguration :

  1. These are available in org.hibernate.cfg package. This is the first class that will be instantiated by hibernate application.
  2. You can use Configuration or AnnotationConfiguration class object for 2 task :
    -> calling configure or configure(String) method.
    -> calling buildSessionFactory() method.
  3. configure() method is responsible for :
    -> reading the data from hibernate configuration document.
    -> reading the data from all the hibernate mapping documents specified in configuration document.
  4. buildSessionFactory() is responsible for creating SessionFactory object.
  5. Configuration or annotation configuration object is single threaded and short lived.
  6. Once SessionFactory object is created then there is no use with Configuration or AnnotationConfiguration object.
SessionFactory :
  1. This interface is available in org.hibernate package.
  2. SessionFactory object is Multi-Threadded and long lived.
  3. When you call buildSessioFactory() method on Configuration object then following task will happen.
    -> set the default to many parameters like batch, size fetch size etc.
    -> generate and catches the sql queries required.
    -> select the Connection provider
    -> select the TransactionFactory.
  4. SessionFactory is :
    -> factory of Session object.
    -> client for connection provider.
    -> client for TransactionFactory.
  5. You need to create one SessionFactory per database.
  6. when you are using multiple databases then you need to write multiple hibernate configuration docs.
Session : 
  1. This is an interface available in org.hibernate package.
  2. Session object is single threaded and short lived.
  3. Session represents period of time where user can do multiple database operation.
  4. Session Object :
    -> uses TransactionFactory to get the transaction.
    -> get the connection from ConnectionProvider.
Transaction :
  1. When transaction is started the following task will happen.
    -> session cache will be created
    -> connection will be taken and will be associated with the current session.
  2. While transaction is running following task will happen.
    -> when any object is participated in session operations, that will be placed in session cache.
  3. When transaction is committed the following task will happen :
    -> session will be flushed(here the synchronization of persistent data with the database will be performed)
    -> session cache will be destroyed
    -> commit will be issued to database
    -> connection will be released

1 comment:

Blog Archive

Ads 468x60px

.

Ads

.

Featured Posts

Popular Posts

Like Us On FaceBook

Total Pageviews

Online Members

Live Traffic