java.lang.NoClassDefFoundError: org/hibernate/engine/SessionFactoryImplementor from Spring 3.1.2/Hibernate 4.1.7 and Shards 3.0.0.Beta2

19,505

Solution 1

I see that you are using HIbernate 4 with spring. So seems like spring & hibernate inter-compatibiity issue. So please visit below site for Hibernate 4 compatibility with spring.

http://blog.springsource.org/2012/04/06/migrating-to-spring-3-1-and-hibernate-4-1/

Else as another option try below version.

<dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>3.3.1.GA</version>
    </dependency>

Solution 2

I too faced the same issue i searched some other sites and its helped me to resolve this issue.What i done wrong is hibernate version i used 4 in maven for transaction manager but in the maven i am configuring the hibernate transaction manager of version 3, that's incompatibility. I changed the spring configuration file like this.

<bean id="hibernateTransactionManager"
        class="org.springframework.orm.hibernate4.HibernateTransactionManager">
    <property name="sessionFactory" ref="sessionFactory" />
</bean>
    <!-- <bean id="hibernateTransactionManager"
        class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory" ref="sessionFactory" />
    </bean> -->
Share:
19,505
Forrest Running
Author by

Forrest Running

In Infinite Reinvention Loop.

Updated on June 13, 2022

Comments

  • Forrest Running
    Forrest Running almost 2 years

    I'm trying a simple Hibernate shard example (Yes, odd, 3.0.0.Beta2 released 4 years ago) using Hibernate Core 4.1.7 and Spring 3.1.2 and hit this issue during session factory initialization:

    Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'mySessionFactory' defined in class path resource [shardedspring-config.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: Factory method [public org.hibernate.SessionFactory it.sella.lab.crm.sys.persistence.ShardedSessionFactoryBuilder.createSessionFactory()] threw exception; nested exception is java.lang.NoClassDefFoundError: org/hibernate/engine/SessionFactoryImplementor
        at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:581)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1015)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:911)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:485)
        at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:456)
        at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:294)
        at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:225)
        at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:291)
        at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:193)
        at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:609)
        at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:918)
        at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:469)
        at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:139)
        at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:83)
        at in.rixx.crm.model.Activity.<clinit>(Activity.java:17)
    

    This is how I pick Spring and Hibernate:

    <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>4.1.7.Final</version>
     </dependency>
     <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-core</artifactId>
            <version>3.1.2.RELEASE</version>
     </dependency> 
    

    This doesn't seem like a issue with shards library - it looks like a general issue caused by refactored SessionFactoryImplementor class. Referring to https://jira.springsource.org/browse/SPR-8885, I've also switched to org.springframework.orm.hibernate4.HibernateTransactionManager for bean 'transactionmanager' - it isn't helping.

    Is there any functional workaround right now for Spring 3.x and Hibernate 4.x?

  • Sarah Elan
    Sarah Elan almost 9 years
    Please include the solution with your answer, since the link might not always be available.