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

  • Spring + Hibernate SessionFactory Problem

    I am using spring + hibernate. I have written following code in application context.xml.

    <bean name="dataSource" class="org.springframework.jdbc.datasource.DriverM anagerDataSource">
    <property name="driverClassName">
    <value>oracle.jdbc.OracleDriver</value>
    </property>
    <property name="url" value="jdbc:oracle:thin:@starbuck.cursci.co.uk:152 1:bmcdev03"/>
    <property name="username" value="webuser"/>
    <property name="password" value="r0ute100"/>
    </bean>

    <bean id="MySessionFactory" class="org.springframework.orm.hibernate3.LocalSes sionFactoryBean">
    <property name="mappingResources">
    <list>
    <value>man.hbm.xml</value>
    </list>
    </property>
    <property name="hibernateProperties">
    <props>
    <prop key="hibernate.dialect">net.sf.hibernate.dialect.O racleDialect</prop>
    <prop key="hibernate.query.substitutions">true=1 false=0</prop>
    <prop key="hibernate.show_sql">true</prop>
    </props>
    </property>
    <property name="dataSource">
    <ref bean="dataSource"/>
    </property>
    </bean>
    <!--bean id="hibernateTemplate" class="org.springframework.orm.hibernate.Hibernate Template">
    <property name="sessionFactory">
    <ref bean="sessionFactory"/>
    </property>
    </bean-->
    <bean class="com.biomedcentral.export.dao.ManDaoImpl" id="ManDao">
    <property name="sessionFactory">
    <ref bean="MySessionFactory"/>
    </property>
    </bean>

    <bean id="ManualhandlerService"
    class="org.springframework.transaction.interceptor .TransactionProxyFactoryBean">
    <property name="target">
    <ref bean="ManualhandlerServiceTarget"/>
    </property>
    </bean>

    <bean id="ManualhandlerServiceTarget"
    class="com.biomedcentral.export.service.Manualhand lerServiceImpl">
    <property name="manDao"><ref bean="manDao"/></property>
    </bean>

    but I am getting following error:

    org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'MySessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.FatalBeanException: Could not instantiate class [org.springframework.orm.hibernate3.LocalSessionFac toryBean]; constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org.hibernate.cfg.Configuration
    org.springframework.beans.FatalBeanException: Could not instantiate class [org.springframework.orm.hibernate3.LocalSessionFac toryBean]; constructor threw exception; nested exception is java.lang.NoClassDefFoundError: org.hibernate.cfg.Configuration
    java.lang.NoClassDefFoundError: org.hibernate.cfg.Configuration
    at org.springframework.orm.hibernate3.LocalSessionFac toryBean.class$(LocalSessionFactoryBean.java:157)
    at org.springframework.orm.hibernate3.LocalSessionFac toryBean.<init>(LocalSessionFactoryBean.java:157)
    at sun.reflect.NativeConstructorAccessorImpl.newInsta nce0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInsta nce(NativeConstructorAccessorImpl.java:39)
    at sun.reflect.DelegatingConstructorAccessorImpl.newI nstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Construc tor.java:274)
    at org.springframework.beans.BeanUtils.instantiateCla ss(BeanUtils.java:100)
    at org.springframework.beans.BeanUtils.instantiateCla ss(BeanUtils.java:76)
    at org.springframework.beans.factory.support.SimpleIn stantiationStrategy.instantiate(SimpleInstantiatio nStrategy.java:49)
    at org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:316)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:226)
    at org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:147)
    at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:269)
    at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:317)
    at org.springframework.web.context.support.AbstractRe freshableWebApplicationContext.refresh(AbstractRef reshableWebApplicationContext.java:134)
    at org.springframework.web.context.ContextLoader.crea teWebApplicationContext(ContextLoader.java:230)
    at org.springframework.web.context.ContextLoader.init WebApplicationContext(ContextLoader.java:156)
    at org.springframework.web.context.ContextLoaderServl et.init(ContextLoaderServlet.java:81)
    at javax.servlet.GenericServlet.init(GenericServlet.j ava:211)
    at org.apache.catalina.core.StandardWrapper.loadServl et(StandardWrapper.java:1029)
    at org.apache.catalina.core.StandardWrapper.load(Stan dardWrapper.java:862)
    at org.apache.catalina.core.StandardContext.loadOnSta rtup(StandardContext.java:4013)
    at org.apache.catalina.core.StandardContext.start(Sta ndardContext.java:4357)
    at org.apache.catalina.core.ContainerBase.addChildInt ernal(ContainerBase.java:823)
    at org.apache.catalina.core.ContainerBase.addChild(Co ntainerBase.java:807)
    at org.apache.catalina.core.StandardHost.addChild(Sta ndardHost.java:595)
    at org.apache.catalina.core.StandardHostDeployer.inst all(StandardHostDeployer.java:277)
    at org.apache.catalina.core.StandardHost.install(Stan dardHost.java:832)
    at org.apache.catalina.manager.ManagerServlet.deploy( ManagerServlet.java:922)
    at org.apache.catalina.manager.ManagerServlet.deploy( ManagerServlet.java:652)
    at org.apache.catalina.manager.ManagerServlet.doPut(M anagerServlet.java:400)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:712)
    at javax.servlet.http.HttpServlet.service(HttpServlet .java:802)
    at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:237)
    at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:157)
    at org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:214)
    at org.apache.catalina.core.StandardValveContext.invo keNext(StandardValveContext.java:104)
    at org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:520)
    at org.apache.catalina.core.StandardContextValve.invo keInternal(StandardContextValve.java:198)
    at org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:152)
    at org.apache.catalina.core.StandardValveContext.invo keNext(StandardValveContext.java:104)
    at org.apache.catalina.authenticator.AuthenticatorBas e.invoke(AuthenticatorBase.java:540)
    at org.apache.catalina.core.StandardValveContext.invo keNext(StandardValveContext.java:102)
    at org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:520)
    at org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:137)
    at org.apache.catalina.core.StandardValveContext.invo keNext(StandardValveContext.java:104)
    at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:118)
    at org.apache.catalina.core.StandardValveContext.invo keNext(StandardValveContext.java:102)
    at org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:520)
    at org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:109)
    at org.apache.catalina.core.StandardValveContext.invo keNext(StandardValveContext.java:104)
    at org.apache.catalina.core.StandardPipeline.invoke(S tandardPipeline.java:520)
    at org.apache.catalina.core.ContainerBase.invoke(Cont ainerBase.java:929)
    at org.apache.coyote.tomcat5.CoyoteAdapter.service(Co yoteAdapter.java:160)
    at org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:799)
    at org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.processConnection(Http11Protocol.jav a:705)
    at org.apache.tomcat.util.net.TcpWorkerThread.runIt(P oolTcpEndpoint.java:577)
    at org.apache.tomcat.util.threads.ThreadPool$ControlR unnable.run(ThreadPool.java:683)
    at java.lang.Thread.run(Thread.java:534)

    could anybody solve this problem?

  • #2
    It looks like your are missing a class. So:
    do you have the hibernate jar in your WEB-INF/lib dir?
    do you work with hibernate 2 or 3? the org.hibernate.cfg.Configuration is from Hibernate 2.. I don`t know if it still there in 3 (I`m not using it).

    Comment


    • #3
      You are mixing HB2(net.sf.hibernate) with HB3 classes (org.hibernate). Inside Spring HB2 is supported under orm.hibernate package, while HB3 under orm.hibernate3 package.

      Comment


      • #4
        thanx..
        I want to use hibernate3 along with spring. I have added hibernate3 jar in web-inf/lib directory. but still getting the same error

        Comment


        • #5
          You have to correct your Spring configuration file - eliminate net.sf.hibernate and replace them with org.hibernate.

          Comment


          • #6
            I have changed configuration file to
            <bean id="MySessionFactory" class="org.springframework.orm.hibernate3.LocalSes sionFactoryBean">
            <property name="mappingResources">
            <list>
            <value>man.hbm.xml</value>
            </list>
            </property>
            <property name="hibernateProperties">
            <props>
            <prop key="hibernate.dialect">org.hibernate.dialect.Orac leDialect</prop>
            </props>
            </property>
            <property name="dataSource">
            <ref bean="dataSource"/>
            </property>
            </bean>

            but still I am getting the same error

            Comment


            • #7
              What about org.springframework.orm.hibernate.HibernateTemplat e to
              org.springframework.orm.hibernate3.HibernateTempla te?

              Comment


              • #8
                I have changed applicationcontext.xml to

                <?xml version="1.0" encoding="UTF-8"?>
                <!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
                <beans>
                <!--<bean id="dataSource" class="org.sprinframework.jndi.JndiObjectFactoryBe an">
                <property name="jndiName">
                <value>java:com/env/jdbc/bmc</value>
                </property>
                </bean>-->
                <bean name="dataSource" class="org.springframework.jdbc.datasource.DriverM anagerDataSource">
                <property name="driverClassName">
                <value>oracle.jdbc.OracleDriver</value>
                </property>
                <property name="url" value="jdbc:oracle:thin:@starbuck.cursci.co.uk:152 1:bmcdev03"/>
                <property name="username" value="webuser"/>
                <property name="password" value="r0ute100"/>
                </bean>

                <bean id="MySessionFactory" class="org.springframework.orm.hibernate3.LocalSes sionFactoryBean">
                <property name="mappingResources">
                <list>
                <value>man.hbm.xml</value>
                </list>
                </property>
                <property name="hibernateProperties">
                <props>
                <prop key="hibernate.dialect">org.hibernate.dialect.Orac leDialect</prop>
                </props>
                </property>
                <property name="dataSource">
                <ref bean="dataSource"/>
                </property>
                </bean>
                <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.Hibernat eTemplate">
                <property name="sessionFactory">
                <ref bean="MySessionFactory"/>
                </property>
                </bean>
                <bean class="com.biomedcentral.export.dao.ManDaoImpl" id="ManDao">
                <property name="hibernateTemplate">
                <ref bean="hibernateTemplate"/>
                </property>
                </bean>

                <bean id="ManualhandlerService"
                class="org.springframework.transaction.interceptor .TransactionProxyFactoryBean">
                <property name="target">
                <ref bean="ManualhandlerServiceTarget"/>
                </property>
                </bean>

                <bean id="ManualhandlerServiceTarget"
                class="com.biomedcentral.export.service.Manualhand lerServiceImpl">
                <property name="manDao"><ref bean="manDao"/></property>
                </bean>

                </beans>

                now i am getting error with hibernatetemplate...

                org.springframework.beans.factory.BeanDefinitionSt oreException: Error registering bean with name 'hibernateTemplate' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Class that bean class [org.springframework.orm.hibernate3.HibernateTempla te] depends on not found; nested exception is java.lang.NoClassDefFoundError: org/hibernate/HibernateException
                org.springframework.beans.factory.xml.DefaultXmlBe anDefinitionParser.parseBeanDefinitionElement(Defa ultXmlBeanDefinitionParser.java:432)
                org.springframework.beans.factory.xml.DefaultXmlBe anDefinitionParser.parseBeanDefinitionElement(Defa ultXmlBeanDefinitionParser.java:335)
                org.springframework.beans.factory.xml.DefaultXmlBe anDefinitionParser.parseBeanDefinitions(DefaultXml BeanDefinitionParser.java:266)
                org.springframework.beans.factory.xml.DefaultXmlBe anDefinitionParser.registerBeanDefinitions(Default XmlBeanDefinitionParser.java:186)
                org.springframework.beans.factory.xml.XmlBeanDefin itionReader.registerBeanDefinitions(XmlBeanDefinit ionReader.java:238)
                org.springframework.beans.factory.xml.XmlBeanDefin itionReader.loadBeanDefinitions(XmlBeanDefinitionR eader.java:155)
                org.springframework.beans.factory.support.Abstract BeanDefinitionReader.loadBeanDefinitions(AbstractB eanDefinitionReader.java:124)
                org.springframework.beans.factory.support.Abstract BeanDefinitionReader.loadBeanDefinitions(AbstractB eanDefinitionReader.java:140)
                org.springframework.web.context.support.XmlWebAppl icationContext.loadBeanDefinitions(XmlWebApplicati onContext.java:116)
                org.springframework.web.context.support.XmlWebAppl icationContext.loadBeanDefinitions(XmlWebApplicati onContext.java:84)
                org.springframework.context.support.AbstractRefres hableApplicationContext.refreshBeanFactory(Abstrac tRefreshableApplicationContext.java:87)
                org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:267)
                org.springframework.web.context.support.AbstractRe freshableWebApplicationContext.refresh(AbstractRef reshableWebApplicationContext.java:134)
                org.springframework.web.context.ContextLoader.crea teWebApplicationContext(ContextLoader.java:230)
                org.springframework.web.context.ContextLoader.init WebApplicationContext(ContextLoader.java:156)
                org.springframework.web.context.ContextLoaderServl et.init(ContextLoaderServlet.java:81)
                javax.servlet.GenericServlet.init(GenericServlet.j ava:211)
                org.apache.catalina.manager.ManagerServlet.deploy( ManagerServlet.java:922)
                org.apache.catalina.manager.ManagerServlet.deploy( ManagerServlet.java:652)
                org.apache.catalina.manager.ManagerServlet.doPut(M anagerServlet.java:400)
                javax.servlet.http.HttpServlet.service(HttpServlet .java:712)
                javax.servlet.http.HttpServlet.service(HttpServlet .java:802)

                Comment


                • #9
                  You have big classpath problems - your libraries are not in there.

                  Comment


                  • #10
                    how to get rid of this error

                    Comment


                    • #11
                      See if you don't have any hb libraries in your classpath - either in tomcat common/lib, shared/lib or inside WEB-INF/lib. Start your application and make sure hibernate is not found.
                      After that get the official Hb3 from hibernate.org (or from Spring-w-deps) and place it in shared/lib. Hibernate has some dependecies - you can read them inside the readme.txt.
                      From there everything should go smooth.

                      Comment


                      • #12
                        I tried to do the same way. But still getting following error

                        org.springframework.beans.factory.BeanCreationExce ption: Error creating bean with name 'MySessionFactory' defined in ServletContext resource [/WEB-INF/applicationContext.xml]: Initialization of bean failed; nested exception is java.lang.NoClassDefFoundError: org/objectweb/asm/Type
                        org.springframework.beans.factory.support.Abstract AutowireCapableBeanFactory.createBean(AbstractAuto wireCapableBeanFactory.java:355)
                        org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:226)
                        org.springframework.beans.factory.support.Abstract BeanFactory.getBean(AbstractBeanFactory.java:147)
                        org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:269)
                        org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:317)
                        org.springframework.web.context.support.AbstractRe freshableWebApplicationContext.refresh(AbstractRef reshableWebApplicationContext.java:134)
                        org.springframework.web.context.ContextLoader.crea teWebApplicationContext(ContextLoader.java:230)
                        org.springframework.web.context.ContextLoader.init WebApplicationContext(ContextLoader.java:156)
                        org.springframework.web.context.ContextLoaderServl et.init(ContextLoaderServlet.java:81)
                        javax.servlet.GenericServlet.init(GenericServlet.j ava:211)
                        org.apache.catalina.manager.ManagerServlet.deploy( ManagerServlet.java:922)
                        org.apache.catalina.manager.ManagerServlet.deploy( ManagerServlet.java:652)
                        org.apache.catalina.manager.ManagerServlet.doPut(M anagerServlet.java:400)
                        javax.servlet.http.HttpServlet.service(HttpServlet .java:712)
                        javax.servlet.http.HttpServlet.service(HttpServlet .java:802)

                        Comment


                        • #13
                          That's a totally different error - read the message and stop wasting your and other's time:
                          Code:
                          org/objectweb/asm/Type
                          You need the dependecies libraries - in this case asm library for cglib.

                          Comment


                          • #14
                            Sorry costin to bother you, but I have already added asm library for cglib.
                            Nways thanx.

                            Comment

                            Working...
                            X