Announcement Announcement Module
Collapse
No announcement yet.
Hibernate with Spring error Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Hibernate with Spring error

    Hi,
    I'm trying to work my way through an example in a Spring book and currently really hating it . Hopefully somebody can help.

    From reading other posts /blogs this afternoon most people are missing a jar file.

    I have both the Spring2.5 and Hibernate3 jars in the library in Eclipse .
    A cut down version of my spring config file is below.
    The error I'm getting seems to be :
    Code:
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/OLStore-servlet.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.hibernate3.LocalSessionFactoryBean]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError
    Below that is this error:
    Code:
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/OLStore-servlet.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.hibernate3.LocalSessionFactoryBean]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError
    Then it traces down to :

    Code:
    java.lang.ClassNotFoundException: org.hibernate.cfg.Configuration
    This is a cut down version of the Spring config file:

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <!--
    in spring 2.0 config file include this header 
     -->
    <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:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
     http://www.springframework.org/schema/aop
     http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
     http://www.springframework.org/schema/tx
     http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
     
    
    <bean id="dataSource" 
    	class="org.springframework.jdbc.datasource.DriverManagerDataSource">
    	<property name="driverClassName"
    	value="com.mysql.jdbc.Driver"/>
    	<property name="url" value="jdbc:mysql://localhost:3307/pnisbett?autoReconnect=true"/>
    	<property name="username" value="root"/>
    	<property name="password" value="" />
    
    </bean>
    
    <bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
    <property name="dataSource" ref="dataSource"/>	
    <property name="mappingResources">
    <list>
    	<value>Entity/Rant.hbm.xml</value>
    	<value>Entity/Person.hbm.xml</value>
    	
    </list>
    </property>
    <property name ="hibernateProperties">
    	<props>
    		<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
    	</props>
    </property>
    
    </bean>
    
    
    
    </beans>
    This is the first part of the stack trace


    Code:
    SEVERE: Context initialization failed
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/OLStore-servlet.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.springframework.orm.hibernate3.LocalSessionFactoryBean]: Constructor threw exception; nested exception is java.lang.NoClassDefFoundError

  • #2
    Hi

    Is your project a maven project? Just wondering if I could take a look. It looks like a missing jar (stating the obvious I know).

    Cheers
    Amin

    Comment


    • #3
      This may not be a missing Hibernate jar, but a dependency *of* Hibernate. You're probably missing one of the ten or so jars required by Hibernate.

      See https://forum.hibernate.org/viewtopi...8503900c62924a for a description of the same exact problem.

      The best way to avoid these issues is to use something like Ivy or Maven to handle dependencies for you. I highly recommend using SpringSource's bundle repository, even if you're not using OSGi. If you choose not to use one of these tools, you simply have to be extremely careful about getting the right deps on the classpath yourself.

      Hope this helps. Good luck!

      Comment


      • #4
        Thanks for the responses . I got it running.
        It was a jar issue.
        I had the jars in the project library but I didn't have the jars in WEB-INF/Lib in Eclipse.

        Basically , I am having a problem with Eclipse .
        I don't know how to view the build files directly without writing an ant file from scratch and dropping it into project.
        For almost all of my projects I've been building them by using 'configure build path' in the project window.

        I know this isn't a Spring issue ,but if anybody knows where eclipse stores it's default build file ,I'd appreciate it.

        Comment

        Working...
        X