Shades88
Shades88

Reputation: 8360

Spring-Hibernate Error: Error loading class [org.springframework.orm.hibernate3.LocalSessionFactoryBean]

I am trying a sample application which uses Spring-Hibernate integration. However I am getting this error when I load config.xml

Exception in thread "main" org.springframework.beans.factory.CannotLoadBeanClassException: Error loading class [org.springframework.orm.hibernate3.LocalSessionFactoryBean] for bean with name 'mySessionFactory' defined in class path resource [SpringDAO/config.xml]: problem with class file or dependent class; nested exception is java.lang.NoClassDefFoundError: org/springframework/dao/support/PersistenceExceptionTranslator

Here's my config.xml code

<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
        http://www.springframework.org/schema/aop
        http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-2.5.xsd">

    <bean id="JdbcDAO" class="SpringDAO.JdbcDAO"/>
    <bean id="HibernateDAO" class="SpringDAO.Hibernate"/>

    <bean id="myDataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
        <property name="url" value="jdbc:mysql://localhost/test"/>
        <property name="username" value="root"/>
        <property name="password" value="password"/>
    </bean>

    <bean id="mySessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
        <property name="dataSource" ref="myDataSource"/>
        <property name="mappingResources">
            <list>
                <value>SpringDAO/HibernateDAO/SocketStreamedData.hbm.xml</value>
            </list>
        </property>
        <property name="hibernateProperties">
            <value>hibernate.dialect=org.hibernate.dialect.HSQLDialect</value>
        </property>
    </bean>

    <bean id="hibernateTemplate"
        class="org.springframework.orm.hibernate3.HibernateTemplate">
        <property name="sessionFactory">
            <ref bean="mySessionFactory"/>
        </property>
    </bean>

    <bean id="socketStreamedDataDAO">
        <property name="hibernateTemplate">
            <ref bean="hibernateTemplate"/>
        </property>
    </bean>
</beans>

Maybe there's something wrong with mappingResources property class is incorrect or something. However, what I have specified there is full classpath for that hibernate xml config. So what could be the problem? Please help me.

Upvotes: 1

Views: 5243

Answers (2)

sanjay
sanjay

Reputation: 31

Please add spring tx jar in your class path.I faced the same issue and solved by adding the spring-tx jar.

Upvotes: 0

LaurentG
LaurentG

Reputation: 11757

Source of a java.lang.NoClassDefFoundError is most of time a problem in classpath. Here you have to check that Spring TX and Hibernate are present in the classpath.

Upvotes: 1

Related Questions