Home  >  Spring Core

AnnotationSessionFactoryBean in Spring

By Arvind Rai, February 09, 2013
AnnotationSessionFactoryBean class belongs to the package org.springframework.orm.hibernate3.annotation. AnnotationSessionFactoryBean is used to create session factory if hibernate pojo are annotated. configLocation is the property to which we assign hibernate.cfg.xml. This session factory is assigned to all dao beans and hibernate template to do database transaction.
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
  <property name="configLocation" ><value>hibernate.cfg.xml</value></property>
</bean>
<bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
	<property name="sessionFactory">
	  <ref bean="sessionFactory" />
	</property>
</bean>
<bean id="pageDao" class="com.concretepage.dao.PageDaoImpl">
    <property name="hibernateTemplate">
	  <ref bean="hibernateTemplate" />
	</property>
</bean>
 
In the above code we can see that bean sessionFactory has been created with AnnotationSessionFactoryBean class. sessionFactory has been assigned to HibernateTemplate and hibernateTemplate bean has been assigned to pageDao bean. Now inside PageDaoImpl we do database transaction.
POSTED BY
ARVIND RAI
ARVIND RAI
FIND MORE TUTORILAS


©2019 concretepage.com | Privacy Policy | Contact Us