I work with Spring 3.1 + Hibernate 4.
I’ve created the following sessionFactory:
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="myDataSource" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">validate</prop>
</props>
</property>
<property name="packagesToScan" value="com.my.company"/>
</bean>
As you see, the above sessionFactory is for Hibernate 4.
I am trying to crate a HibernateTemplate (org.springframework.orm.hibernate3.HibernateTemplate) through Java code, by that sessionFactory, but I am not sure how to do this.
I’ve tried the following code:
@Resource(name="sessionFactory")
public void setSessionFactory(LocalSessionFactoryBean sessionFactory) {
this.hibernateTemplate = new HibernateTemplate(sessionFactory.getObject());
}
But I’m getting the following error message:
org.springframework.beans.factory.BeanNotOfRequiredTypeException: Bean named 'sessionFactory' must be of type [org.springframework.orm.hibernate4.LocalSessionFactoryBean], but was actually of type [org.hibernate.internal.SessionFactoryImpl]
Could you show how to do this?
As from this post:
From the javadoc of package org.springframework.orm.hibernate4: