Announcement Announcement Module
Collapse
No announcement yet.
Please Help. Hibernate will not work for me Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Please Help. Hibernate will not work for me

    Hello,
    I am trying to set up hibernate in spring. I have this code in my applicationcontext

    Code:
    <?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="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
            <property name="location" value="/WEB-INF/jdbc.properties"/>
        </bean>
        
        <!-- 
        <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
            <property name="driverClassName" value="${jdbc.driverClassName}"/>
            <property name="url" value="${jdbc.url}"/>
            <property name="username" value="${jdbc.username}"/>
            <property name="password" value="${jdbc.password}"/>
        </bean>
        -->
        
        <!-- ADD PERSISTENCE SUPPORT HERE (jpa, hibernate, etc) -->
        <!-- DataSource Property -->
        <bean id="defaultDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" lazy-init="true">
            <property name="driverClassName" value="com.mysql.jdbc.Driver"/>
            <property name="url" value="jdbc:mysql://localhost:3306/confessions"/>
            <property name="username" value="root"/>
            <property name="password" value="301085"/>
        </bean>
        
        <bean id="hbSessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean" lazy-init="true">
            <property name="dataSource" ref="defaultDataSource"/>
            <property name="mappingResources">
              <list>
                <value>com/confessions/DataSource/DAO/Confession.hbm.xml</value>            
              </list>
            </property>
            <property name="hibernateProperties">
              <value>
                hibernate.dialect=org.hibernate.dialect.MySQLDialect
                show_sql=false
              </value>
            </property>
        </bean>   
        
        <bean id="hibernateTemplate" 
            class="org.springframework.orm.hibernate3.HibernateTemplate">
            <property name="sessionFactory" ref="hbSessionFactory"/>
        </bean>
    
    
        <!-- Services -->
        <bean id="confessionsService" class="com.confessions.Service.UsableConfessionsService" lazy-init="true">
        </bean>    
    
    </beans>
    When i run it, it says "the requested resource is unavailable.

    I went thruogh the applicationcontext and tried to troubleshoot what coudl cause the error. i have noticed that when i remove this code then everything works perfectly.
    Code:
      <bean id="hibernateTemplate" class="org.springframework.orm.hibernate3.HibernateTemplate">
        <property name="sessionFactory">
          <ref bean="hbSessionFactory"/>
        </property>
      </bean>

    I am not sure if i need to initialize the hibernatetemplate bean. Can anyone PLEASE shed some light on this problem. i am completely stumped.

    I would appreciate it a lot for any help.

    thanks.
    Last edited by netvampire; Jul 18th, 2007, 06:34 PM.

  • #2
    Post the full strack trace that you are getting.

    Comment


    • #3
      thanks for responding. When i try to deploy the web app with the bean id=hibernatetemplate included i get this

      Code:
      HTTP Status 404 - /Confessions/
      
      --------------------------------------------------------------------------------
      
      type Status report
      
      message /Confessions/
      
      description The requested resource (/Confessions/) is not available.
      
      
      --------------------------------------------------------------------------------
      
      Apache Tomcat/5.5.17


      When I remove the bean id="hibernatetemplate" declaration, i can load my application just fine.

      Comment


      • #4
        Post the relevant portion of the server error log

        You can find it in <tomcat_folder/logs/ folder, and it will be called something like:

        Code:
        C:\opt\apache-tomcat-5.5.20\logs\catalina.2007-07-02.log
        Cheers
        Rick

        Comment


        • #5
          Here we go. it is split across two posts:

          Code:
          18-Jul-2007 7:57:37 PM org.apache.catalina.core.AprLifecycleListener init
          INFO: The Apache Tomcat Native library which allows optimal performance in production environments was not found on the java.library.path: C:\Program Files\Java\jdk1.6.0_01\bin;.;C:\Windows\Sun\Java\bin;C:\Windows\system32;C:\Windows;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Program Files\Common Files\Roxio Shared\DLLShared\;C:\Program Files\Common Files\Roxio Shared\DLLShared\;C:\Program Files\Common Files\Roxio Shared\9.0\DLLShared\;c:\Program Files\Bioscrypt\VeriSoft\bin;C:\Program Files\Java\jdk1.6.0_01\bin;C:\Program Files\MySQL\MySQL Server 5.0\bin
          18-Jul-2007 7:57:37 PM org.apache.coyote.http11.Http11Protocol init
          INFO: Initializing Coyote HTTP/1.1 on http-8080
          18-Jul-2007 7:57:37 PM org.apache.catalina.startup.Catalina load
          INFO: Initialization processed in 530 ms
          18-Jul-2007 7:57:37 PM org.apache.catalina.core.StandardService start
          INFO: Starting service Catalina
          18-Jul-2007 7:57:37 PM org.apache.catalina.core.StandardEngine start
          INFO: Starting Servlet Engine: Apache Tomcat/6.0.8
          18-Jul-2007 7:57:37 PM org.apache.catalina.core.StandardHost start
          INFO: XML validation disabled
          18-Jul-2007 7:57:38 PM org.apache.myfaces.config.FacesConfigurator feedStandardConfig
          INFO: Reading standard config org/apache/myfaces/resource/standard-faces-config.xml
          18-Jul-2007 7:57:38 PM org.apache.myfaces.config.FacesConfigurator feedWebAppConfig
          INFO: Reading config /WEB-INF/faces-config.xml
          18-Jul-2007 7:57:38 PM org.apache.myfaces.config.FacesConfigurator logMetaInf
          INFO: Starting up MyFaces-package : myfaces-api in version : 1.1.5 from path : file:/C:/Web/apache-tomcat-6.0.8/webapps/gr8marks/WEB-INF/lib/myfaces-api-1.1.5.jar
          18-Jul-2007 7:57:38 PM org.apache.myfaces.config.FacesConfigurator logMetaInf
          INFO: Starting up MyFaces-package : myfaces-impl in version : 1.1.5 from path : file:/C:/Web/apache-tomcat-6.0.8/webapps/gr8marks/WEB-INF/lib/myfaces-impl-1.1.5.jar
          18-Jul-2007 7:57:38 PM org.apache.myfaces.config.FacesConfigurator logMetaInf
          INFO: MyFaces-package : tomahawk-sandbox not found.
          18-Jul-2007 7:57:38 PM org.apache.myfaces.config.FacesConfigurator logMetaInf
          INFO: MyFaces-package : tomahawk not found.
          18-Jul-2007 7:57:39 PM org.apache.myfaces.config.FacesConfigurator handleSerialFactory
          INFO: Serialization provider : class org.apache.myfaces.shared_impl.util.serial.DefaultSerialFactory
          18-Jul-2007 7:57:39 PM org.apache.myfaces.webapp.StartupServletContextListener initFaces
          INFO: ServletContext 'C:\Web\apache-tomcat-6.0.8\webapps\gr8marks\' initialized.
          18-Jul-2007 7:57:42 PM org.apache.catalina.core.StandardContext resourcesStart
          SEVERE: Error starting static Resources
          java.lang.IllegalArgumentException: Document base C:\Web\apache-tomcat-6.0.8\webapps\WebApplication1 does not exist or is not a readable directory
          	at org.apache.naming.resources.FileDirContext.setDocBase(FileDirContext.java:141)
          	at org.apache.catalina.core.StandardContext.resourcesStart(StandardContext.java:3941)
          	at org.apache.catalina.core.StandardContext.start(StandardContext.java:4112)
          	at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:760)
          	at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:740)
          	at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:525)
          	at org.apache.catalina.startup.HostConfig.deployDescriptor(HostConfig.java:626)
          	at org.apache.catalina.startup.HostConfig.deployDescriptors(HostConfig.java:553)
          	at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:488)
          	at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1138)
          	at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:311)
          	at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:120)
          	at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1022)
          	at org.apache.catalina.core.StandardHost.start(StandardHost.java:719)
          	at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1014)
          	at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)
          	at org.apache.catalina.core.StandardService.start(StandardService.java:451)
          	at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)
          	at org.apache.catalina.startup.Catalina.start(Catalina.java:552)
          	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
          	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
          	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
          	at java.lang.reflect.Method.invoke(Method.java:597)
          	at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)
          	at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)
          18-Jul-2007 7:57:42 PM org.apache.catalina.core.StandardContext start
          SEVERE: Error in resourceStart()
          18-Jul-2007 7:57:42 PM org.apache.catalina.core.StandardContext start
          SEVERE: Error getConfigured
          18-Jul-2007 7:57:42 PM org.apache.catalina.core.StandardContext start
          SEVERE: Context [/WebApplication1] startup failed due to previous errors
          18-Jul-2007 7:57:42 PM org.apache.catalina.core.StandardContext stop
          INFO: Container org.apache.catalina.core.ContainerBase.[Catalina].[localhost].[/WebApplication1] has not been started
          18-Jul-2007 7:57:42 PM org.apache.catalina.startup.HostConfig deployWAR
          INFO: Deploying web application archive Confessions.war
          18-Jul-2007 7:57:43 PM org.apache.catalina.core.StandardContext start
          SEVERE: Error listenerStart
          18-Jul-2007 7:57:43 PM org.apache.catalina.core.StandardContext start
          SEVERE: Context [/Confessions] startup failed due to previous errors
          18-Jul-2007 7:57:44 PM com.sun.faces.config.rules.RendererRule end
          WARNING: [RendererRule]{faces-config/render-kit/renderer} Merge(com.exadel.vcp.components.Header,com.exadel.vcp.renderers.HeaderRenderer)
          18-Jul-2007 7:57:44 PM com.sun.faces.config.rules.RendererRule end
          WARNING: [RendererRule]{faces-config/render-kit/renderer} Merge(com.exadel.vcp.components.Header,com.exadel.vcp.renderers.HeaderRenderer)
          18-Jul-2007 7:57:44 PM com.sun.faces.config.rules.RendererRule end
          WARNING: [RendererRule]{faces-config/render-kit/renderer} Merge(com.exadel.vcp.components.Header,com.exadel.vcp.renderers.HeaderRenderer)
          18-Jul-2007 7:57:44 PM com.sun.faces.config.rules.RendererRule end
          WARNING: [RendererRule]{faces-config/render-kit/renderer} Merge(com.exadel.vcp.components.Header,com.exadel.vcp.renderers.HeaderRenderer)

          Comment


          • #6
            Code:
            
            18-Jul-2007 7:57:44 PM com.sun.faces.config.rules.RendererRule end
            WARNING: [RendererRule]{faces-config/render-kit/renderer} Merge(com.exadel.vcp.components.Header,com.exadel.vcp.renderers.HeaderRenderer)
            18-Jul-2007 7:57:44 PM com.sun.faces.config.rules.ComponentRule end
            WARNING: [ComponentRule]{faces-config/component} Merge(javax.faces.ViewRoot)
            18-Jul-2007 7:57:46 PM org.apache.myfaces.config.FacesConfigurator feedStandardConfig
            INFO: Reading standard config org/apache/myfaces/resource/standard-faces-config.xml
            18-Jul-2007 7:57:46 PM org.apache.myfaces.config.FacesConfigurator feedWebAppConfig
            INFO: Reading config /WEB-INF/faces-config.xml
            18-Jul-2007 7:57:46 PM org.apache.myfaces.config.FacesConfigurator logMetaInf
            INFO: Starting up MyFaces-package : myfaces-api in version : 1.1.5 from path : file:/C:/Web/apache-tomcat-6.0.8/webapps/ajax/WEB-INF/lib/myfaces-api-1.1.5.jar
            18-Jul-2007 7:57:46 PM org.apache.myfaces.config.FacesConfigurator logMetaInf
            INFO: Starting up MyFaces-package : myfaces-impl in version : 1.1.5 from path : file:/C:/Web/apache-tomcat-6.0.8/webapps/ajax/WEB-INF/lib/myfaces-impl-1.1.5.jar
            18-Jul-2007 7:57:46 PM org.apache.myfaces.config.FacesConfigurator logMetaInf
            INFO: MyFaces-package : tomahawk-sandbox not found.
            18-Jul-2007 7:57:46 PM org.apache.myfaces.config.FacesConfigurator logMetaInf
            INFO: MyFaces-package : tomahawk not found.
            18-Jul-2007 7:57:46 PM org.apache.myfaces.shared_impl.util.LocaleUtils toLocale
            WARNING: Locale name in faces-config.xml null or empty, setting locale to default locale : en_CA
            18-Jul-2007 7:57:46 PM org.apache.myfaces.config.FacesConfigurator handleSerialFactory
            INFO: Serialization provider : class org.apache.myfaces.shared_impl.util.serial.DefaultSerialFactory
            18-Jul-2007 7:57:46 PM org.apache.myfaces.webapp.StartupServletContextListener initFaces
            INFO: ServletContext 'C:\Web\apache-tomcat-6.0.8\webapps\ajax\' initialized.
            18-Jul-2007 7:57:48 PM org.apache.catalina.loader.WebappClassLoader validateJarFile
            INFO: validateJarFile(C:\Web\apache-tomcat-6.0.8\webapps\Bookstore\WEB-INF\lib\servlet-2.2.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class
            18-Jul-2007 7:57:48 PM org.apache.catalina.loader.WebappClassLoader validateJarFile
            INFO: validateJarFile(C:\Web\apache-tomcat-6.0.8\webapps\Bookstore - Copy\WEB-INF\lib\servlet-2.2.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class
            18-Jul-2007 7:57:49 PM org.apache.myfaces.config.FacesConfigurator feedStandardConfig
            INFO: Reading standard config org/apache/myfaces/resource/standard-faces-config.xml
            18-Jul-2007 7:57:49 PM org.apache.myfaces.config.FacesConfigurator feedClassloaderConfigurations
            INFO: Reading config jar:file:/C:/Web/apache-tomcat-6.0.8/webapps/e-boats/WEB-INF/lib/tomahawk-1.1.3.jar!/META-INF/faces-config.xml
            18-Jul-2007 7:57:49 PM org.apache.myfaces.config.FacesConfigurator feedContextSpecifiedConfig
            WARNING: /WEB-INF/faces-config.xml has been specified in the javax.faces.CONFIG_FILES context parameter of the deployment descriptor. This should be removed, as it will be loaded twice.  See JSF spec 1.1, 10.3.2
            18-Jul-2007 7:57:49 PM org.apache.myfaces.config.FacesConfigurator feedContextSpecifiedConfig
            INFO: Reading config /WEB-INF/faces-config.xml
            18-Jul-2007 7:57:49 PM org.apache.myfaces.config.FacesConfigurator feedWebAppConfig
            INFO: Reading config /WEB-INF/faces-config.xml
            18-Jul-2007 7:57:49 PM org.apache.myfaces.shared_impl.util.LocaleUtils toLocale
            WARNING: Locale name in faces-config.xml null or empty, setting locale to default locale : en_CA
            18-Jul-2007 7:57:49 PM org.apache.myfaces.webapp.StartupServletContextListener initFaces
            INFO: ServletContext 'C:\Web\apache-tomcat-6.0.8\webapps\e-boats\' initialized.
            18-Jul-2007 7:57:49 PM org.apache.myfaces.webapp.StartupServletContextListener handleSerialFactory
            INFO: Serialization provider : class org.apache.myfaces.shared_impl.util.serial.DefaultSerialFactory
            18-Jul-2007 7:57:50 PM org.apache.coyote.http11.Http11Protocol start
            INFO: Starting Coyote HTTP/1.1 on http-8080
            18-Jul-2007 7:57:50 PM org.apache.jk.common.ChannelSocket init
            INFO: Port busy 8009 java.net.BindException: Address already in use: JVM_Bind
            18-Jul-2007 7:57:50 PM org.apache.jk.common.ChannelSocket init
            INFO: JK: ajp13 listening on /0.0.0.0:8010
            18-Jul-2007 7:57:50 PM org.apache.jk.server.JkMain start
            INFO: Jk running ID=1 time=0/32  config=null
            18-Jul-2007 7:57:50 PM org.apache.catalina.startup.Catalina start
            INFO: Server startup in 12683 ms


            I looked through it briefly and can not find anything. After the server started up, I DID visit the web site url in hopes of generating a detailed error. Unfortuantely nothign came up.

            Comment


            • #7
              The problem is in the Hibernate or DataSource configuration. It kind of a works if you comment out the HibernateTemplate part because SessionFactory and DataSource are marked as lazy-inited.


              Delete the lazy-init parts from the configuration, redeploy and then find the deployment error in the logs.

              Comment


              • #8
                I'd also recommend writing a simple unit test to see what's going on. It will speed up the development cycle.
                Last edited by karldmoore; Aug 27th, 2007, 05:05 PM.

                Comment


                • #9
                  Thanks for the info. I will delete lazy-init and create a test module tonight. I will let you know how it goes. Thanks again for the help.

                  Comment


                  • #10
                    Okay, I removed the lazy-init lines from my applicationContext file.
                    I ran the application, and the web browser still asys the resource is not found. I looked in the log and found nothing that could tell me what the error was.

                    I whipped up a quick test application taht looks like this
                    Code:
                    public class Test {
                        
                        /** Creates a new instance of Test */
                        public Test() {
                        }
                    
                        public static void main(String args[]){
                            ApplicationContext appContext = new ClassPathXmlApplicationContext("WEB-INF/applicationContext.xml");
                    
                            //Get the service reference
                            ConfessionsService service = (ConfessionsService)appContext.getBean("confessionService");
                    
                            //Add new currency
                            Confession newCurrency = new Confession();
                            newCurrency.setPost("HELLO WORLD ");
                            service.addConfession(newCurrency);
                    
                        }
                        
                    }

                    This application did not work, however it did give me this bit of error. Apparently the applicationContext file can not be found. How do i describe that it is located in the web-inf folder.


                    Code:
                    log4j:WARN No appenders could be found for logger (org.springframework.core.CollectionFactory).
                    log4j:WARN Please initialize the log4j system properly.
                    Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [WEB-INF/applicationContext.xml]; nested exception is java.io.FileNotFoundException: class path resource [WEB-INF/applicationContext.xml] cannot be opened because it does not exist
                    Caused by: java.io.FileNotFoundException: class path resource [WEB-INF/applicationContext.xml] cannot be opened because it does not exist
                            at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:137)
                            at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:351)
                            at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:334)
                            at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:126)
                            at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:142)
                            at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:168)
                            at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:113)
                            at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:79)
                            at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:94)
                            at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:294)
                            at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:92)
                            at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:77)
                            at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:68)
                            at com.confessions.DataSource.DAO.Test.main(Test.java:25)
                    Java Result: 1



                    Can someone post there applicationContext file with the hibernate bean definitions. It would help me out a lot, especially if you are using mysql.thanks

                    Comment


                    • #11
                      This isn't on the classpath hence it can't be found, you just need to add the classpath reference and rerun.
                      Last edited by karldmoore; Aug 27th, 2007, 05:05 PM.

                      Comment


                      • #12
                        how do i add the classpath reference

                        Comment


                        • #13
                          You should be able to select the folder you want and click add to classpath.
                          Last edited by karldmoore; Aug 27th, 2007, 05:05 PM.

                          Comment


                          • #14
                            would anyone just be able to post there applicationContext.xml file so that I may use it as a reference. It would be greatly appreciated.

                            Comment


                            • #15
                              Problem Might Not Be Hibernate

                              This log message suggests that Hibernate isn't the problem:

                              Caused by: java.io.FileNotFoundException: class path resource [WEB-INF/applicationContext.xml] cannot be opened because it does not exist

                              Can't find your app context XML.

                              %

                              Comment

                              Working...
                              X