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

Related Posts:

  • Hibernate Fetching Strategies Today i am going to tell you what are the Hibernate Fetching Strategies and how to use that in order to tune the performance of your applications. So these are the fetching strategies in hibernate : join fetching(fetch="jo… Read More
  • What is n+1 problem and how to solve it N+1 is one of the most famous question among java developers. It will give some performance issue if you where working on a large project. So it's better to resolve it using some below techniques. What is n+1 problem ? Ans… Read More
  • Open Session In View(OSIV) Once the session is closed you can not be able to access the data from detached object and if you do you will get a LazyInitializationException: Session has been closed. It means that your session and session transaction is… Read More
  • Hibernate Architecture Configuration or AnnotationConfiguration : These are available in org.hibernate.cfg package. This is the first class that will be instantiated by hibernate application. You can use Configuration or AnnotationConfigurati… Read More
  • Alternatives of Open Session In View(OSIV) Today I am going to tell you other alternative you can do in order to avoid LazyInitializationException: Session has been closed. If you are using SPRING with HIBERNATE that you can take the advantages of IOC and AOP. These … Read More

1 comment:

Blog Archive

Ads 468x60px

.

Ads

.

Featured Posts

Popular Posts

Like Us On FaceBook

Total Pageviews

201976

Online Members

Live Traffic