title: H2 database c3p0 proxy with hibernate. Could not load driverClass org.h2.Drive
body: <p>I'm working on my project Spring MVC, Hibernate and H2 Database. Before I moved from MySQL to H2 everything was working perfectly fine on MySQL. After so of the changes from MySQL to H2 database I have this:</p>
  
  <pre><code>2013-07-18 15:40:01,193 DEBUG [com.mchange.v2.resourcepool.BasicResourcePool] - &lt;acquire test -- pool size: 0; target_pool_size: 3; desired target? 1&gt;
  2013-07-18 15:40:01,193 DEBUG [com.mchange.v2.resourcepool.BasicResourcePool] - &lt;awaitAvailable(): [unknown]&gt;
  2013-07-18 15:40:01,194 DEBUG [com.mchange.v2.resourcepool.BasicResourcePool] - &lt;trace com.mchange.v2.resourcepool.BasicResourcePool@19f9444 [managed: 0, unused: 0, excluded: 0]&gt;
  2013-07-18 15:40:01,192 WARN [com.mchange.v2.c3p0.DriverManagerDataSource] - &lt;Could not load driverClass org.h2.Drive&gt;
  java.lang.ClassNotFoundException: org.h2.Drive
      at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1676)
      at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1521)
      at java.lang.Class.forName0(Native Method)
      at java.lang.Class.forName(Class.java:186)
      at com.mchange.v2.c3p0.DriverManagerDataSource.ensureDriverLoaded(DriverManagerDataSource.java:100)
      at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:132)
      at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182)
      at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171)
      at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)
      at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1014)
      at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32)
      at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1810)
      at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)
  2013-07-18 15:40:01,192 WARN [com.mchange.v2.c3p0.DriverManagerDataSource] - &lt;Could not load driverClass org.h2.Drive&gt;
  java.lang.ClassNotFoundException: org.h2.Drive
      at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1676)
      at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1521)
      at java.lang.Class.forName0(Native Method)
      at java.lang.Class.forName(Class.java:186)
      at com.mchange.v2.c3p0.DriverManagerDataSource.ensureDriverLoaded(DriverManagerDataSource.java:100)
      at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:132)
      at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182)
      at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171)
      at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)
      at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1014)
      at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32)
      at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1810)
      at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)
  2013-07-18 15:40:01,194 DEBUG [com.mchange.v2.resourcepool.BasicResourcePool] - &lt;An exception occurred while acquiring a poolable resource. Will retry.&gt;
  java.sql.SQLException: No suitable driver
      at java.sql.DriverManager.getDriver(DriverManager.java:289)
      at com.mchange.v2.c3p0.DriverManagerDataSource.driver(DriverManagerDataSource.java:223)
      at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:134)
      at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182)
      at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171)
      at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)
      at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1014)
      at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32)
      at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1810)
      at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)
  2013-07-18 15:40:01,194 DEBUG [com.mchange.v2.resourcepool.BasicResourcePool] - &lt;An exception occurred while acquiring a poolable resource. Will retry.&gt;
  java.sql.SQLException: No suitable driver
      at java.sql.DriverManager.getDriver(DriverManager.java:289)
      at com.mchange.v2.c3p0.DriverManagerDataSource.driver(DriverManagerDataSource.java:223)
      at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:134)
      at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:182)
      at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:171)
      at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)
      at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1014)
      at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourcePool.java:32)
      at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicResourcePool.java:1810)
      at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)
  2013-07-18 15:40:01,194 DEBUG [com.mchange.v2.resourcepool.BasicResourcePool] - &lt;An exception occurred while acquiring a poolable resource. Will retry.&gt;
  </code></pre>
  
  <p>Seems it can not load H2 database driver from anywhere, I have it in my class path, even twice I load it from Maven and manually as a usual library. I also checked my datasource twice everything is correct.</p>
  
  <p>My app-config:</p>
  
  <pre><code>        &lt;bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"&gt; &lt;!-- Using and configuring C3P0 proxy --&gt;
          &lt;property name="driverClass"&gt;&lt;value&gt;org.h2.Drive&lt;/value&gt;&lt;/property&gt;
          &lt;property name="jdbcUrl"&gt;&lt;value&gt;jdbc:h2:/home/vadim/workspace-sts/h2/EDUCATION&lt;/value&gt;&lt;/property&gt;
          &lt;property name="user"&gt;&lt;value&gt;sa&lt;/value&gt;&lt;/property&gt;
          &lt;property name="password"&gt;&lt;value&gt;&lt;/value&gt;&lt;/property&gt;
          &lt;property name="initialPoolSize"&gt;&lt;value&gt;3&lt;/value&gt;&lt;/property&gt; &lt;!-- Number of Connections a pool will try to acquire upon startup --&gt;
          &lt;property name="minPoolSize"&gt;&lt;value&gt;1&lt;/value&gt;&lt;/property&gt; &lt;!-- Minimum connection pool size --&gt;
          &lt;property name="maxPoolSize"&gt;&lt;value&gt;20&lt;/value&gt;&lt;/property&gt; &lt;!-- Max connection pool size --&gt;
          &lt;property name="maxConnectionAge"&gt;&lt;value&gt;3600&lt;/value&gt;&lt;/property&gt; &lt;!-- Set max connection age to 1 hour, after it will release --&gt;
          &lt;property name="maxIdleTime"&gt;&lt;value&gt;600&lt;/value&gt;&lt;/property&gt; &lt;!-- 10 minutes connection can stay unused before be discarded --&gt;
          &lt;property name="checkoutTimeout"&gt;&lt;value&gt;240000&lt;/value&gt;&lt;/property&gt; &lt;!-- Each what time check for unused connections --&gt;
          &lt;/bean&gt;
  
      &lt;!-- Declare Hibernate transaction manager. Realization of PlatformTransactionManager--&gt;
      &lt;bean id="transactionManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager"&gt;
          &lt;property name="sessionFactory" ref ="sessionFactory"/&gt;
      &lt;/bean&gt;
  
      &lt;tx:advice  id="txAdvice" transaction-manager="transactionManager"&gt;
          &lt;tx:attributes&gt;
              &lt;tx:method name="fetch*" propagation="REQUIRED" read-only="true" /&gt;
              &lt;tx:method name="*"/&gt;
          &lt;/tx:attributes&gt;    
      &lt;/tx:advice&gt;
  
      &lt;aop:config&gt;
          &lt;aop:pointcut id="eduWebPointcuts" expression="execution(* edu.demidov.service.EducationWebServiceImpl.*(..))"/&gt;
          &lt;aop:advisor advice-ref="txAdvice" pointcut-ref="eduWebPointcuts"/&gt; 
      &lt;/aop:config&gt;
  
      &lt;!-- Looks for specific annotation configuration in this packages --&gt;
      &lt;context:component-scan base-package="edu.demidov.dao, edu.demidov.service"/&gt;
  
      &lt;!-- Declare annotation configuration --&gt;
      &lt;context:annotation-config /&gt;
  
      &lt;!-- Build sessionFactory annotation base configuration --&gt;
      &lt;bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean"&gt;
  
          &lt;property name="dataSource" ref ="dataSource"/&gt; &lt;!-- Injecting datasource C3P0 to Hibernate sessionFactory datasource --&gt;
          &lt;property name="packagesToScan" value="edu.demidov.dto"/&gt; &lt;!-- Package will be scanned for entity classes --&gt;
  
          &lt;property name="hibernateProperties"&gt;   &lt;!-- Configuring properties --&gt;
              &lt;props&gt; 
  
                  &lt;prop key="hibernate.dialect"&gt; org.hibernate.dialect.H2Dialect&lt;/prop&gt; &lt;!-- Put dialect for particular database to use queries to this DB --&gt;
                  &lt;prop key="show_sql"&gt;true&lt;/prop&gt;
  
  
                  &lt;prop key="hibernate.c3p0.min_size"&gt;1&lt;/prop&gt; &lt;!-- Same to minPoolSize --&gt;
                  &lt;prop key="hibernate.c3p0.max_size"&gt;20&lt;/prop&gt; &lt;!--Same to maxPoolSize --&gt;
                  &lt;prop key="hibernate.c3p0.timeout"&gt;600&lt;/prop&gt; &lt;!-- Same to maxIdleTime --&gt;
                  &lt;prop key="hibernate.c3p0.max_statements"&gt;5&lt;/prop&gt; &lt;!-- Set number of cached statements used often --&gt;
  
                  &lt;prop key="hibernate.max_fetch_depth"&gt;3&lt;/prop&gt;  &lt;!-- Sets a maximum "depth" for the outer join fetch tree for single-ended associations (one-to-one, many-to-one) --&gt;
                  &lt;prop key="hibernate.jdbc.fetch_size"&gt;30&lt;/prop&gt; &lt;!-- Declare how many records will get from database in one package --&gt;
                  &lt;prop key="hibernate.jdbc.batch_size"&gt;15&lt;/prop&gt; &lt;!-- When it's a lot of queries in short time passed to database this put queries in one batch and send them to database --&gt;
                  &lt;prop key="hibernate.show_sql"&gt;true&lt;/prop&gt;
  
              &lt;/props&gt;
         &lt;/property&gt; &lt;!-- End of configuration hibernateProperties --&gt;
  
      &lt;/bean&gt; &lt;!-- End of configuring org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean --&gt;
  
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>My web.xml</p>
  
  <pre><code>&lt;context-param&gt;
          &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
          &lt;param-value&gt;
              /WEB-INF/spring/root-context.xml
             /WEB-INF/spring/app-Confing.xml
          &lt;/param-value&gt;
      &lt;/context-param&gt;
  
      &lt;!-- Creates the Spring Container shared by all Servlets and Filters --&gt;
      &lt;listener&gt;
          &lt;listener-class&gt;org.springframework.web.context.ContextLoaderListener&lt;/listener-class&gt;
      &lt;/listener&gt;
  
      &lt;!-- Processes application requests --&gt;
      &lt;servlet&gt;
          &lt;servlet-name&gt;appServlet&lt;/servlet-name&gt;
          &lt;servlet-class&gt;org.springframework.web.servlet.DispatcherServlet&lt;/servlet-class&gt;
          &lt;init-param&gt;
              &lt;param-name&gt;contextConfigLocation&lt;/param-name&gt;
              &lt;param-value&gt;/WEB-INF/spring/appServlet/servlet-context.xml&lt;/param-value&gt;
          &lt;/init-param&gt;
          &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
      &lt;/servlet&gt;
  
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;appServlet&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  
  &lt;/web-app&gt;
  </code></pre>