Autowiring is happening perfectly and everything works fine.
But i need to know how session factory is injected in HibernateTransactionManager
using LocalSessionFactoryBean
though
no relation between LocalSessionFactoryBean
class and SessionFactory
interface.
PFB the code i used in my project
<beans:bean id="transactionManager"
class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<beans:property name="sessionFactory"
ref="localSessionFactoryBean" />
</beans:bean>
<beans:bean id="localSessionFactoryBean"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<beans:property name="dataSource" ref="dataSource" />
<beans:property name="hibernateProperties">
<beans:props>
<beans:prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect
</beans:prop>
<beans:prop key="hibernate.show_sql">true</beans:prop>
</beans:props>
</beans:property>
</beans:bean>
In the above code, I am injecting LocalSessionFactoryBean
for sessionFactory
in HibernateTransactionManager
.
Please, explain how sessionFactory
is initialized in HibernateTransactionManager
from LocalSessionFactoryBean
using annotation driven in detail.
LocalSessionFactoryBean
implements FactoryBean<SessionFactory>
. So when Spring sets sessionFactory
to the HibernateTransactionManager
it calls getObject()
methods of LocalSessionFactoryBean
and gets SessionFactory
.
public class LocalSessionFactoryBean extends HibernateExceptionTranslator
implements FactoryBean<SessionFactory> {
public SessionFactory getObject() {
return this.sessionFactory;
}
}