title: c3p0 pooling is not working (with hibernate and a datasource, on tomcat)
body: <p>We have a java web application running on tomcat 6, which is calling a jar for persistance. This jar is located in the tomcat lib folder, and uses a tomcat datasource :</p>
  
  <pre><code>&lt;Resource name="jdbc/mydatasource"
            auth="Container"
            type="javax.sql.DataSource"
            username="USER"
            password="PASSWORD"
            driverClassName="org.postgresql.Driver"
            url="jdbc:postgresql://HOST:5432/DATABASE"/&gt;
  </code></pre>
  
  <p>The jar is the binary of a java project, which uses hibernate 3.5.6-Final for ORM.
  The hibernate configuration is the following :</p>
  
  <pre><code>    &lt;property name="hibernate.c3p0.min_size"&gt;5&lt;/property&gt;
      &lt;property name="hibernate.c3p0.max_size"&gt;20&lt;/property&gt;
      &lt;property name="hibernate.c3p0.timeout"&gt;1800&lt;/property&gt;
      &lt;property name="hibernate.c3p0.max_statements"&gt;50&lt;/property&gt;
      &lt;property name="hibernate.connection.datasource"&gt;java:jdbc/mydatasource&lt;/property&gt; 
      &lt;property name="dialect"&gt;org.hibernate.dialect.PostgreSQLDialect&lt;/property&gt; 
  </code></pre>
  
  <p>At first, we did not include the hibernate-c3p0 bundle in the application, so the c3p0 settings were not used. And the whole application works fine like this.</p>
  
  <p>We added the hibernate-c3p0 bundle, in order to enable a better pooling management. So this bundle is now embedded in the jar for persistance.</p>
  
  <p>But we have now this error (it appears after each startup, when the weba pplication tries to retrieve data from the persistance jar) :</p>
  
  <blockquote>
    <p>[Task-Thread-for-com.mchange.v2.async.ThreadPerTaskAsynchronousRunner@eafa5f] 13
    :46:22 WARN - BasicResourcePool$AcquireTask: () com.mchange.v2.resourcepool.Basi
    cResourcePool$AcquireTask@b321c1 -- Acquisition Attempt Failed!!! Clearing pendi
    ng acquires. While trying to acquire a needed new resource, we failed to succeed
     more than the maximum number of allowed acquisition attempts (30). Last acquisi
    tion attempt exception:
    java.lang.NullPointerException
            at sun.jdbc.odbc.JdbcOdbcDriver.getProtocol(JdbcOdbcDriver.java:507)
            at sun.jdbc.odbc.JdbcOdbcDriver.knownURL(JdbcOdbcDriver.java:476)
            at sun.jdbc.odbc.JdbcOdbcDriver.acceptsURL(JdbcOdbcDriver.java:307)
            at java.sql.DriverManager.getDriver(DriverManager.java:253)
            at com.mchange.v2.c3p0.DriverManagerDataSource.driver(DriverManagerDataS
    ource.java:224)
            at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManag
    erDataSource.java:120)
            at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnecti
    on(WrapperConnectionPoolDataSource.java:143)
            at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnecti
    on(WrapperConnectionPoolDataSource.java:132)
            at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionRe
    sourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:137)
            at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResource
    Pool.java:1014)
            at com.mchange.v2.resourcepool.BasicResourcePool.access$800(BasicResourc
    ePool.java:32)
            at com.mchange.v2.resourcepool.BasicResourcePool$AcquireTask.run(BasicRe
    sourcePool.java:1810)
            at com.mchange.v2.async.ThreadPerTaskAsynchronousRunner$TaskThread.run(T
    hreadPerTaskAsynchronousRunner.java:255)</p>
  </blockquote>
  
  <p>This seems wrong because the Ojdbc driver seems to be used instead of the postgresql driver defined in the datasource.</p>
  
  <p>Do you know what can make this error appear, and how to solve it ?</p>
  
  <p>I tried different things in the hibernate configuration, that i found in stackoverflow and different forums, which do not solve the problem :</p>
  
  <pre><code>&lt;property name="hibernate.connection.provider_class"&gt;org.hibernate.connection.C3P0ConnectionProvider&lt;/property&gt;
  
      &lt;property name="hibernate.connection.driver_class"&gt;org.postgresql.Driver&lt;/property&gt;
      &lt;property name="driverClass"&gt;org.postgresql.Driver&lt;/property&gt;
      &lt;property name="hibernate.c3p0.driverClass"&gt;org.postgresql.Driver&lt;/property&gt;
  </code></pre>
  
  <p>I must precise that we only have under our control the jar used for persistance and the tomcat installation. We cannot modify the web application which is calling the jar.</p>