spring-projects / spring-framework

Spring Framework
https://spring.io/projects/spring-framework
Apache License 2.0
56.62k stars 38.13k forks source link

NoClassDefFoundError: org/hibernate/engine/SessionFactoryImplementor thrown from SessionFactoryUtils when using LocalSessionFactoryBuilder [SPR-8885] #13526

Closed spring-projects-issues closed 12 years ago

spring-projects-issues commented 12 years ago

Alex Barnes opened SPR-8885 and commented

I just updated my Maven dependency to Spring 3.1.RC2 and whilst playing around I decided to upgrade my Hibernate dependency to 4.0.0.CR6. I have existing code which configures a SessionFactory using @Configuration. I appreciate that the LocalSessionFactoryBuilder#buildSessionFactory method is deprecated but it appears that SessionFactoryUtils is not compatible with the new layout in Hibernate 4. Specifically SessionFactoryImplementor has moved from org.hibernate.engine to org.hibernate.engine.spi.

return new LocalSessionFactoryBuilder(dataSource)
  .addAnnotatedClasses(Spot.class, SupportedBuoy.class)
  .addProperties(properties).buildSessionFactory();

Full stack track:

Caused by: java.lang.NoClassDefFoundError: org/hibernate/engine/SessionFactoryImplementor
    at org.springframework.orm.hibernate3.SessionFactoryUtils.getDataSource(SessionFactoryUtils.java:121)
    at org.springframework.orm.hibernate3.HibernateTransactionManager.afterPropertiesSet(HibernateTransactionManager.java:411)
    at org.springframework.orm.hibernate3.HibernateTransactionManager.<init>(HibernateTransactionManager.java:174)
    at com.devcentre.app.config.HibernateConfiguration.transactionManager(HibernateConfiguration.java:75)
    at com.devcentre.app.config.HibernateConfiguration$$EnhancerByCGLIB$$e2ff8f9b.CGLIB$transactionManager$1(<generated>)
    at com.devcentre.app.config.HibernateConfiguration$$EnhancerByCGLIB$$e2ff8f9b$$FastClassByCGLIB$$3db91f52.invoke(<generated>)
    at net.sf.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:167)
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:279)
    at com.devcentre.app.config.HibernateConfiguration$$EnhancerByCGLIB$$e2ff8f9b.transactionManager(<generated>)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:149)

Affects: 3.1 RC2

spring-projects-issues commented 12 years ago

Alex Barnes commented

OK, so I went to all the trouble of typing this up without spending the required time to understand exactly what was going on. I needed to be using a org.springframework.orm.hibernate4.HibernateTransactionManager.

Please close me.

spring-projects-issues commented 12 years ago

Chris Beams commented

No problem, Alex. Thanks for following up.