spring: java.lang.ClassNotFoundException: org.hibernate.engine.SessionFactoryImplementor

1- Problem

Using spring 4 and hibernate 3.6.10 and got this

Caused by: java.lang.NoClassDefFoundError: org/hibernate/engine/spi/SessionFactoryImplementor
  at org.springframework.orm.hibernate4.SessionFactoryUtils.(SessionFactoryUtils.java:92) ~[spring-orm-4.0.2.RELEASE.jar:4.0.2.RELEASE]
  at org.springframework.orm.hibernate4.HibernateTransactionManager.afterPropertiesSet(HibernateTransactionManager.java:335) ~[spring-orm-4.0.2.RELEASE.jar:4.0.2.RELEASE]
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1612) ~[spring-beans-4.0.2.RELEASE.jar:4.0.2.RELEASE]
  at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1549) ~[spring-beans-4.0.2.RELEASE.jar:4.0.2.RELEASE]
  ... 28 common frames omitted
Caused by: java.lang.ClassNotFoundException: org.hibernate.engine.spi.SessionFactoryImplementor
  at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1702) ~[catalina.jar:7.0.50]
  at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1547) ~[catalina.jar:7.0.50]
  ... 32 common frames omitted

2-Solution

Using right version Hibernate for transaction manager and Local session factory bean

  • org.springframework.orm.hibernate3.HibernateTransactionManager
  • org.springframework.orm.hibernate3.LocalSessionFactoryBean

 

<beans:bean id="sessionFactory" name="sessionFactory"
        class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <beans:property name="configLocation">
           <beans:value>classpath:hibernate.cfg.xml</beans:value>
        </beans:property>
        <beans:property name="hibernateProperties">
            <beans:props>
                <beans:prop key="hibernate.show_sql">true</beans:prop>
            </beans:props>
        </beans:property>
    </beans:bean>
<beans:bean id="transactionManager"
        class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <beans:property name="sessionFactory" ref="sessionFactory" />
    </beans:bean>

Leave a Reply