Can use same Session Factory for Two Hibernate Templates
Question
Is there some mechanism to use one session factory for two hibernate templates.
I have try and it throw bean creation exception.
<bean id="auditLogHibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="auditLogSessionFactory"/>
</bean>
<bean id="auditLogLocalHibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="auditLogSessionFactory"/>
</bean>
Can I do this. If Cant let me to know any other way to do it. Or cant we do this any way ?
Stack trace
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'auditLogLocalHibernateTemplate' defined in class path resource [auditlog/conf/auditlog-conf.xml]: Cannot resolve reference to bean 'localHibernateSession' while setting bean property 'sessionFactory'; nested exception is org.springframework.beans.factory.BeanCurrentlyInCreationException: Error creating bean with name 'appHibernateSessionFactory': FactoryBean which is currently in creation returned null from getObject
full configuration as below.
<alias name="appHibernateSessionFactory" alias="localHibernateSession" />
<bean id="auditLogSessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="auditLogDataSource"/>
<property name="annotatedClasses">
<list>
<value>auditlog.domain.AuditLog</value>
</list>
</property>
<property name="hibernateProperties" ref="auditLogHibernateProperties" />
</bean>
<bean id="auditLogHibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="auditLogSessionFactory"/>
</bean>
<bean id="auditLogLocalHibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
<property name="sessionFactory" ref="localHibernateSession"/>
</bean>
<bean id="auditLogDao" class="auditlog.dao.AuditLogDao" >
<property name="hibernateTemplate" ref="auditLogHibernateTemplate" />
</bean>
<bean id="auditLogLocalDao" class="auditlog.dao.AuditLogLocalDao" >
<property name="hibernateTemplate" ref="auditLogLocalHibernateTemplate" />
</bean>
<bean id="auditLogManager" class="auditlog.service.AuditLogManager" >
<property name="auditLogDao" ref="auditLogDao" />
<property name="auditLogLocalDao" ref="auditLogLocalDao" />
</bean>
No correct solution