Announcement Announcement Module
Collapse
No announcement yet.
Unable to create Hibernate SessionFactory Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Unable to create Hibernate SessionFactory

    Hey everyone, I'm trying to integrate Hibernate with Spring, and I'm lost. When I try to run the servlet, I get this error:

    Code:
    org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'sessionFactory' defined in ServletContext resource [/WEB-INF/rentaBikeApp-servlet.xml]: Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: null
    	org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:370)
    	org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:226)
    	org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:147)
    	org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:269)
    	org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:318)
    	org.springframework.web.context.support.AbstractRefreshableWebApplicationContext.refresh(AbstractRefreshableWebApplicationContext.java:134)
    	org.springframework.web.servlet.FrameworkServlet.createWebApplicationContext(FrameworkServlet.java:305)
    	org.springframework.web.servlet.FrameworkServlet.initWebApplicationContext(FrameworkServlet.java:250)
    	org.springframework.web.servlet.FrameworkServlet.initServletBean(FrameworkServlet.java:219)
    	org.springframework.web.servlet.HttpServletBean.init(HttpServletBean.java:112)
    	javax.servlet.GenericServlet.init(GenericServlet.java:211)
    	org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
    	org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
    	org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:825)
    	org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:738)
    	org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:526)
    	org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
    	org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
    	java.lang.Thread.run(Thread.java:595)
    Here is part of my servlet.xml configuration file for Spring:

    Code:
        <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
            <property name="driverClassName">
                <value>org.postgresql.Driver</value>
            </property>
            <property name="url">
                <value>jdbc:postgresql://localhost/bikestore</value>
            </property>
            <property name="username">
                <value>Postgres</value>
            </property>
            <property name="password">
                <value>postgres</value>
            </property>
        </bean>
        
        <bean id="sessionFactory" class="org.springframework.orm.hibernate.LocalSessionFactoryBean">
            <property name="dataSource"><ref bean="dataSource"/></property>
            <property name="mappingResources">
                <list>
                    <value>Bike.hbm.xml</value>
                    <value>Customer.hbm.xml</value>
                    <value>Reservation.hbm.xml</value>
                </list>
            </property>
            <property name="hibernateProperties">
                <props>
                    <prop key="hibernate.dialect">
                        net.sf.hibernate.dialect.PostgreSQLDialext
                    </prop>
                </props>
            </property>
        </bean>
    It's been giving me this exception a lot, but previously it actually had a class missing, and I just needed to add some more libraries into my classpath. I'm not sure what to do about this, though.

  • #2
    Strange that the error doesn't show what class is not found. To find out what classes (jar) you need deploy only the session factory appContext with as little beans as possible. By looking at your appContext you need commons-dbcp, hibernate, spring, postgres-jdbc driver and their dependencies in classpath. I know it's not much but the 'null' exception doesn't say anything at all..

    Comment


    • #3
      The only one of those that I was missing was commons-dbcp, but adding it doesn't help. I'm deploying with only the two beans listed in my first post, but it's not giving me anything new. Is there anything specific I should be looking for?

      Comment


      • #4
        A couple of things I can think of:

        i) Are you using Hibernate2 or Hibernate3? The session factory bean from spring has to correspond. The one listed is for Hibernate 2.

        ii) Hibernate has a number of other dependencies, but if they are missing they are usually obvious from the stack trace. Look in the readme files from hibernate to find out which are needed (cglib, asm, odmg, ehcache if memory serves, but this also differs between H2 and H3 so check their emails).

        Jonny

        Comment


        • #5
          Alright, I got it working by importing everything in hibernate/lib. Thanks for your help.

          Comment

          Working...
          X