title: Configuring C3P0 in Persistence.xml with JPA and Hibernate
body: <p>Well, i'm trying to configure for first time the C3P0 with JPA + Hibernate + Spring. In persistence.xml i have:</p>
  
  <pre><code>&lt;properties&gt;
      &lt;property name="hibernate.show_sql" value="false" /&gt;
      &lt;property name="hibernate.format_sql" value="false" /&gt;
      &lt;property name="hibernate.hbm2ddl.auto" value="update" /&gt;
      &lt;property name="hibernate.cache.use_second_level_cache"
          value="false" /&gt;
      &lt;property name="hibernate.cache.use_query_cache" value="false" /&gt;
      &lt;property name="hibernate.jdbc.batch_size" value="50" /&gt;
  
      &lt;!-- Important --&gt;
      &lt;property name="hibernate.connection.provider_class"
          value="org.hibernate.connection.C3P0ConnectionProvider" /&gt;
  
      &lt;property name="hibernate.c3p0.max_size" value="20" /&gt;
      &lt;property name="hibernate.c3p0.min_size" value="5" /&gt;
      &lt;property name="hibernate.c3p0.acquire_increment" value="1" /&gt;
      &lt;property name="hibernate.c3p0.idle_test_period" value="3000" /&gt;
      &lt;property name="hibernate.c3p0.max_statements" value="50" /&gt;
      &lt;property name="hibernate.c3p0.timeout" value="300" /&gt;
  &lt;/properties&gt;
  </code></pre>
  
  <p>But when i try to initialize the tomcat, i got the following error:</p>
  
  <pre><code>Caused by: com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source.
      at com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1319)
      at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:557)
      at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:477)
      at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:525)
      ... 58 more
  50570 [Thread-4] ERROR org.hibernate.tool.hbm2ddl.SchemaUpdate - could not complete schema update
  java.sql.SQLException: Connections could not be acquired from the underlying database!
      at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:106)
      at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:529)
  </code></pre>
  
  <p>EDIT 1:</p>
  
  <p>This is my applicationContext.xml, how can i configure C3P0 inside this ?</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
      xmlns:tx="http://www.springframework.org/schema/tx"
      xsi:schemaLocation="http://www.springframework.org/schema/beans 
          http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
          http://www.springframework.org/schema/context
          http://www.springframework.org/schema/context/spring-context-3.0.xsd
          http://www.springframework.org/schema/tx
          http://www.springframework.org/schema/tx/spring-tx-3.0.xsd"&gt;
  
      &lt;!-- Seta anotaçoes para serem usadas pelo Spring --&gt;
      &lt;context:annotation-config /&gt;
  
      &lt;!-- Define o pacote onde o Spring vai procurar por beans anotados --&gt;
      &lt;context:component-scan base-package="br.com.myapp" /&gt;
  
      &lt;!-- define que as transaçoes irao ser anotadas --&gt;
      &lt;tx:annotation-driven proxy-target-class="true" /&gt;
  
      &lt;!-- Configuracao do Banco de Dados --&gt;
      &lt;bean id="dataSource"
          class="org.springframework.jdbc.datasource.DriverManagerDataSource"&gt;
          &lt;property name="driverClassName" value="org.postgresql.Driver" /&gt;
          &lt;property name="url" value="jdbc:postgresql://localhost/mydatabase" /&gt;
          &lt;property name="username" value="postgres" /&gt;
          &lt;property name="password" value="pgadmin" /&gt;
      &lt;/bean&gt;
  
      &lt;!-- Configuracao do Hibernate --&gt;
      &lt;bean id="entityManagerFactory"
          class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt;
          &lt;property name="persistenceUnitName" value="senderPU" /&gt;
          &lt;property name="dataSource" ref="dataSource" /&gt;
          &lt;property name="jpaVendorAdapter"&gt;
              &lt;bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"&gt;
                  &lt;property name="databasePlatform" value="org.hibernate.dialect.PostgreSQLDialect" /&gt;
                  &lt;property name="showSql" value="true" /&gt;
              &lt;/bean&gt;
          &lt;/property&gt;
      &lt;/bean&gt;
  
      &lt;!-- Configuracao do gerente de transacoes do Spring --&gt;
      &lt;bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"&gt;
          &lt;property name="entityManagerFactory" ref="entityManagerFactory" /&gt;
      &lt;/bean&gt;
  
  &lt;/beans&gt;
  </code></pre>