We can directly pass the session factory object or can pass hibernate template class as well in the subclasses of HibernateDoaSupport. HibernateDaoSupport is an abstract class is similar to JDBCDaoSupport approach of Spring Data Access and is a wrapper on top of Hibernate template. Sample Configuration of HibernateTemplate class as follows HibernateTemplate does provides several convenient method like save, update, saveOrUpdate, persist, delete etc corresponding to Hibernate API and these method handles creation/ closing of session internally. Hibernate template class depends on session factory so we need to define a session factory and provide its reference using sessionFactory property. Depending on the hibernate version we can useįor hibernate 3 - 3.HibernateTemplateįor hibernate 4- 4.HibernateTemplate HibernateTemplate class is similar to JDBC Templates approach of Spring Data Access. Note- LocalSessionFactoryBean and AnnotationSessionFactoryBean classes are innermost classes and other two approaches are dependent on any one these approaches. Sample configuration of AnnotationSessionFactory class is Important properties of AnnotationSessionFactoryBean are –ī) annotatedClasses - this property is of list type and is used to map the entity classes This is subclass of LocalSessionFactoryBean class and is used for Annotation based hibernate entities (hibernate version 3). In case you are using Hibernate4 with annotated entity beans then use annotatedClasses property to map annotated classes. Sample Example of LocalSessionFactoryBean configuration is įor hibernate 4 we just need to change the class to ![]() Important properties of LocalSessionFactoryBean are –Ī) datasource- is used to provide the reference of data sourceī) mappingResources- this property is of list type and is used to map the hbm filesĬ) hibernateProperties- is used to provide the hibernate properties (that we configure in file) as a key value pair. ![]() If we are using hibernate4 then 4.LocalSessionFactoryBean and for hibernate3 use 3.LocalSessionFactoryBean This factory bean works for XML based hibernate and is depending on the version of hibernate, we need to use the LocalSessionFactoryBean. 23.2.1 LocalSessionFactoryBean –Īs its name suggests, this factory bean is responsible to create the hibernate session factories. There are multiple ways we can use to integrate Spring with hibernate. We all know Spring and hibernate both are popular frameworks and so a lot can be achieved using both together. We saw how to use Hibernate in standalone Java applications and in web applications in the earlier chapter and in this chapter, we will discuss how to integrate hibernate with Spring Framework.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |