SessionFactory contains all the hibernate mapping informations and it is responsible for creation and maintenance of the hibernate session in a transaction.

 

Application obtains session instances from Session Factory. SessionFactory is mostly configured asSingleton in application , If you are using Spring it will be configured in application context to be made singleton.

SessionFactory caches generate SQL statements and other mapping metadata that Hibernate uses at runtime.

Cached data that has been read in one unit of work and may be reused in a future unit of work.

You can obtain object of session factory from Configuration class

SessionFactory sessionFactory =
Configuration.buildSessionFactory();  

Here in your conf. you have configured sessionFactory using AnnotationSessionFactoryBean class

bean id="mySessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">

and you have set some properties of session factory those are needed.

HibernateTemplate is a class provided by Spring :

Helper class that simplifies Hibernate data access code. Automatically converts HibernateExceptions into DataAccessExceptions, following the org.springframework.dao exception hierarchy.

Advertisements