Announcement Announcement Module
Collapse
No announcement yet.
Initializing DataSource Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Initializing DataSource

    Hi,
    I have a file named hibernate.properties file which includes the (driver class name, url, username and password) of the database.
    I want values of the properties in this file to be added when the application is run for the first time.
    The user enters them from a certain form in the application.
    But, unfortunately I can't do this because on loading the application it searches for the values (and they are not found) so I get the following exception:

    Code:
    ERROR ContainerBackgroundProcessor[StandardEngine[Catalina]] org.hibernate.util.JDBCExceptionReporter - Cannot create JDBCdriver of class '' for connect URL ''
    ERROR ContainerBackgroundProcessor[StandardEngine[Catalina]] org.hibernate.tool.hbm2ddl.SchemaUpdate - could not get database metadata
    org.apache.commons.dbcp.SQLNestedException: Cannot create JDBC driver of class '' for connect URL ''
            at org.apache.commons.dbcp.BasicDataSource.createDataSource(BasicDataSource.java:780)
            at org.apache.commons.dbcp.BasicDataSource.getConnection(BasicDataSource.java:540)
            at org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider.getConnection(LocalDataSourceConnectionProvider.java:80)
            at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute(SchemaUpdate.java:118)
            at org.hibernate.impl.SessionFactoryImpl.<init>&#40;SessionFactoryImpl.java&#58;265&#41;
            at org.hibernate.cfg.Configuration.buildSessionFactory&#40;Configuration.java&#58;1005&#41;
            at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory&#40;LocalSessionFactoryBean.java&#58;746&#41;
            at org.springframework.orm.hibernate3.LocalSessionFactoryBean.afterPropertiesSet&#40;LocalSessionFactoryBean.java&#58;673&#41;
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods&#40;AbstractAutowireCapableBeanFactory.java&#58;962&#41;
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean&#40;AbstractAutowireCapableBeanFactory.java&#58;354&#41;
            at org.springframework.beans.factory.support.AbstractBeanFactory.getBean&#40;AbstractBeanFactory.java&#58;223&#41;
            at org.springframework.beans.factory.support.AbstractBeanFactory.getBean&#40;AbstractBeanFactory.java&#58;147&#41;
            at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference&#40;BeanDefinitionValueResolver.java&#58;176&#41;
            at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary&#40;BeanDefinitionValueResolver.java&#58;105&#41;
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues&#40;AbstractAutowireCapableBeanFactory.java&#58;916&#41;
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean&#40;AbstractAutowireCapableBeanFactory.java&#58;727&#41;
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean&#40;AbstractAutowireCapableBeanFactory.java&#58;336&#41;
            at org.springframework.beans.factory.support.AbstractBeanFactory.getBean&#40;AbstractBeanFactory.java&#58;223&#41;
            at org.springframework.beans.factory.support.AbstractBeanFactory.getBean&#40;AbstractBeanFactory.java&#58;147&#41;
            at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference&#40;BeanDefinitionValueResolver.java&#58;176&#41;
            at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary&#40;BeanDefinitionValueResolver.java&#58;105&#41;
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues&#40;AbstractAutowireCapableBeanFactory.java&#58;916&#41;
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean&#40;AbstractAutowireCapableBeanFactory.java&#58;727&#41;
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean&#40;AbstractAutowireCapableBeanFactory.java&#58;336&#41;
            at org.springframework.beans.factory.support.AbstractBeanFactory.getBean&#40;AbstractBeanFactory.java&#58;223&#41;
            at org.springframework.beans.factory.support.AbstractBeanFactory.getBean&#40;AbstractBeanFactory.java&#58;147&#41;
            at org.springframework.context.support.AbstractApplicationContext.getBean&#40;AbstractApplicationContext.java&#58;536&#41;
            at org.springframework.context.support.AbstractApplicationContext.initMessageSource&#40;AbstractApplicationContext.java&#58;406&#41;
            at org.springframework.context.support.AbstractApplicationContext.refresh&#40;AbstractApplicationContext.java&#58;300&#41;
            at org.springframework.web.context.support.AbstractRefreshableWebApplicationContext.refresh&#40;AbstractRefreshableWebApplicationContext.java&#58;134&#41;
            at org.springframework.web.context.ContextLoader.createWebApplicationContext&#40;ContextLoader.java&#58;230&#41;
            at org.springframework.web.context.ContextLoader.initWebApplicationContext&#40;ContextLoader.java&#58;156&#41;
            at org.springframework.web.context.ContextLoaderListener.contextInitialized&#40;ContextLoaderListener.java&#58;48&#41;
            at org.apache.catalina.core.StandardContext.listenerStart&#40;StandardContext.java&#58;3631&#41;
            at org.apache.catalina.core.StandardContext.start&#40;StandardContext.java&#58;4065&#41;
            at org.apache.catalina.core.ContainerBase.addChildInternal&#40;ContainerBase.java&#58;755&#41;
            at org.apache.catalina.core.ContainerBase.addChild&#40;ContainerBase.java&#58;739&#41;
            at org.apache.catalina.core.StandardHost.addChild&#40;StandardHost.java&#58;525&#41;
            at org.apache.catalina.startup.HostConfig.deployDirectory&#40;HostConfig.java&#58;886&#41;
            at org.apache.catalina.startup.HostConfig.deployDirectories&#40;HostConfig.java&#58;849&#41;
            at org.apache.catalina.startup.HostConfig.deployApps&#40;HostConfig.java&#58;474&#41;
            at org.apache.catalina.startup.HostConfig.check&#40;HostConfig.java&#58;1142&#41;
            at org.apache.catalina.startup.HostConfig.lifecycleEvent&#40;HostConfig.java&#58;292&#41;
            at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent&#40;LifecycleSupport.java&#58;119&#41;
            at org.apache.catalina.core.ContainerBase.backgroundProcess&#40;ContainerBase.java&#58;1293&#41;
            at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren&#40;ContainerBase.java&#58;1553&#41;
            at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren&#40;ContainerBase.java&#58;1562&#41;
            at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run&#40;ContainerBase.java&#58;1542&#41;
            at java.lang.Thread.run&#40;Thread.java&#58;595&#41;
    Caused by&#58; java.sql.SQLException&#58; No suitable driver
            at java.sql.DriverManager.getDriver&#40;DriverManager.java&#58;243&#41;
            at org.apache.commons.dbcp.BasicDataSource.createDataSource&#40;BasicDataSource.java&#58;773&#41;
            ... 48 more
    ERROR ContainerBackgroundProcessor&#91;StandardEngine&#91;Catalina&#93;&#93; org.hibernate.tool.hbm2ddl.SchemaUpdate - could not complete schema update
    org.apache.commons.dbcp.SQLNestedException&#58; Cannot create JDBC driver of class '' for connect URL ''
            at org.apache.commons.dbcp.BasicDataSource.createDataSource&#40;BasicDataSource.java&#58;780&#41;
            at org.apache.commons.dbcp.BasicDataSource.getConnection&#40;BasicDataSource.java&#58;540&#41;
            at org.springframework.orm.hibernate3.LocalDataSourceConnectionProvider.getConnection&#40;LocalDataSourceConnectionProvider.java&#58;80&#41;
            at org.hibernate.tool.hbm2ddl.SchemaUpdate.execute&#40;SchemaUpdate.java&#58;118&#41;
            at org.hibernate.impl.SessionFactoryImpl.<init>&#40;SessionFactoryImpl.java&#58;265&#41;
            at org.hibernate.cfg.Configuration.buildSessionFactory&#40;Configuration.java&#58;1005&#41;
            at org.springframework.orm.hibernate3.LocalSessionFactoryBean.newSessionFactory&#40;LocalSessionFactoryBean.java&#58;746&#41;
            at org.springframework.orm.hibernate3.LocalSessionFactoryBean.afterPropertiesSet&#40;LocalSessionFactoryBean.java&#58;673&#41;
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods&#40;AbstractAutowireCapableBeanFactory.java&#58;962&#41;
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean&#40;AbstractAutowireCapableBeanFactory.java&#58;354&#41;
            at org.springframework.beans.factory.support.AbstractBeanFactory.getBean&#40;AbstractBeanFactory.java&#58;223&#41;
            at org.springframework.beans.factory.support.AbstractBeanFactory.getBean&#40;AbstractBeanFactory.java&#58;147&#41;
            at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference&#40;BeanDefinitionValueResolver.java&#58;176&#41;
            at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary&#40;BeanDefinitionValueResolver.java&#58;105&#41;
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues&#40;AbstractAutowireCapableBeanFactory.java&#58;916&#41;
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean&#40;AbstractAutowireCapableBeanFactory.java&#58;727&#41;
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean&#40;AbstractAutowireCapableBeanFactory.java&#58;336&#41;
            at org.springframework.beans.factory.support.AbstractBeanFactory.getBean&#40;AbstractBeanFactory.java&#58;223&#41;
            at org.springframework.beans.factory.support.AbstractBeanFactory.getBean&#40;AbstractBeanFactory.java&#58;147&#41;
            at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference&#40;BeanDefinitionValueResolver.java&#58;176&#41;
            at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary&#40;BeanDefinitionValueResolver.java&#58;105&#41;
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues&#40;AbstractAutowireCapableBeanFactory.java&#58;916&#41;
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean&#40;AbstractAutowireCapableBeanFactory.java&#58;727&#41;
            at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean&#40;AbstractAutowireCapableBeanFactory.java&#58;336&#41;
            at org.springframework.beans.factory.support.AbstractBeanFactory.getBean&#40;AbstractBeanFactory.java&#58;223&#41;
            at org.springframework.beans.factory.support.AbstractBeanFactory.getBean&#40;AbstractBeanFactory.java&#58;147&#41;
            at org.springframework.context.support.AbstractApplicationContext.getBean&#40;AbstractApplicationContext.java&#58;536&#41;
            at org.springframework.context.support.AbstractApplicationContext.initMessageSource&#40;AbstractApplicationContext.java&#58;406&#41;
            at org.springframework.context.support.AbstractApplicationContext.refresh&#40;AbstractApplicationContext.java&#58;300&#41;
            at org.springframework.web.context.support.AbstractRefreshableWebApplicationContext.refresh&#40;AbstractRefreshableWebApplicationContext.java&#58;134&#41;
            at org.springframework.web.context.ContextLoader.createWebApplicationContext&#40;ContextLoader.java&#58;230&#41;
            at org.springframework.web.context.ContextLoader.initWebApplicationContext&#40;ContextLoader.java&#58;156&#41;
            at org.springframework.web.context.ContextLoaderListener.contextInitialized&#40;ContextLoaderListener.java&#58;48&#41;
            at org.apache.catalina.core.StandardContext.listenerStart&#40;StandardContext.java&#58;3631&#41;
            at org.apache.catalina.core.StandardContext.start&#40;StandardContext.java&#58;4065&#41;
            at org.apache.catalina.core.ContainerBase.addChildInternal&#40;ContainerBase.java&#58;755&#41;
            at org.apache.catalina.core.ContainerBase.addChild&#40;ContainerBase.java&#58;739&#41;
            at org.apache.catalina.core.StandardHost.addChild&#40;StandardHost.java&#58;525&#41;
            at org.apache.catalina.startup.HostConfig.deployDirectory&#40;HostConfig.java&#58;886&#41;
            at org.apache.catalina.startup.HostConfig.deployDirectories&#40;HostConfig.java&#58;849&#41;
            at org.apache.catalina.startup.HostConfig.deployApps&#40;HostConfig.java&#58;474&#41;
            at org.apache.catalina.startup.HostConfig.check&#40;HostConfig.java&#58;1142&#41;
            at org.apache.catalina.startup.HostConfig.lifecycleEvent&#40;HostConfig.java&#58;292&#41;
            at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent&#40;LifecycleSupport.java&#58;119&#41;
            at org.apache.catalina.core.ContainerBase.backgroundProcess&#40;ContainerBase.java&#58;1293&#41;
            at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren&#40;ContainerBase.java&#58;1553&#41;
            at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren&#40;ContainerBase.java&#58;1562&#41;
            at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run&#40;ContainerBase.java&#58;1542&#41;
            at java.lang.Thread.run&#40;Thread.java&#58;595&#41;
    Caused by&#58; java.sql.SQLException&#58; No suitable driver
            at java.sql.DriverManager.getDriver&#40;DriverManager.java&#58;243&#41;
            at org.apache.commons.dbcp.BasicDataSource.createDataSource&#40;BasicDataSource.java&#58;773&#41;
            ... 48 more
    How could I prevent the application from trying to load these values at the begining and loads them after the values are added to the hibernate.properties file.

    Thanks in Advance.
    Sherihan.

  • #2
    Sherihan,

    I think the problem here lies in the fact that your DataSource is needed at startup to perform the schema update. Have you configured Hibernate to update the database schema (hbm2ddl) when the SessionFactory starts?

    Rob

    Comment


    • #3
      Hi Rob,
      yes I did.
      But the problem is that at startup no values are avaialble for the datasource.
      When the application runs for the fist time the user should be able to configure the datasource.

      Thanks.
      Sherihan

      Comment

      Working...
      X