Issue
I am migrating an old app from Spring 4 to 5. It builds fine with Maven, but when I start the app in jboss 7.1, I get this error:
java.lang.ClassNotFoundException: org.springframework.orm.hibernate4.LocalSessionFactoryBean
Spring 5.3.20
/>
Hibernate 5.3.28.Final
I have been following this guide, https://github.com/spring-projects/spring-framework/wiki/Upgrading-to-Spring-Framework-5.x
This said Hibernate 5 is required, so I updated that in the pom to 5.3.28.Final
Here is relevant snippet of spring-context.xml:
<bean id="hibernateSessionFactory"
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="annotatedClasses">
<list>
<value>com.mycompany.bean.FooService</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</prop>
<prop key="show_sql">true</prop>
</props>
</property>
</bean>
Running with Java 8.
Solution
You need to replace org.springframework.orm.hibernate4.LocalSessionFactoryBean
with org.springframework.orm.hibernate5.LocalSessionFactoryBean
.
The relevant parts of the migration guide are:
Hibernate support has been upgraded to a Hibernate ORM 5.2+ baseline, with a focus on ORM 5.4.x.
This indicates that the minimum version of Hibernate is now Hibernate 5.2.
and
Packages
web.view.tiles2
andorm.hibernate3/hibernate4
dropped.
This indicates that the package your XML config is using (org.springframework.orm.hibernate4
) no longer exists. Searching for LocalSessionFactoryBean
in the Spring Framework 5.3.22 apidoc shows org.springframework.orm.hibernate5.LocalSessionFactoryBean
. Its API seems compatible with your XML definition, so changing the class
property should be all that you need to change.
Answered By - Mark Rotteveel
Answer Checked By - Pedro (JavaFixing Volunteer)