title: Hibernate/c3p0 : Connection pool is full : "pool is already maxed out" error
body: <p>I work with Hibernate and c3p0 to manage DAO in my application.</p>
  
  <p>There is problem after a while : the application, more precisely BDD requests, does not work. Reason : the connection pool is full.</p>
  
  <p>I have the following messages : </p>
  
  <pre><code>com.mchange.v2.resourcepool.BasicResourcePool - acquire test -- pool is already maxed out. [managed: 20; max: 20]
  com.mchange.v2.resourcepool.BasicResourcePool@240ab5e6 [managed: 20, unused: 0, excluded: 0] (e.g. com.mchange.v2.c3p0.impl.NewPooledConnection@547a79cf)
  </code></pre>
  
  <p>It seems that connections are never closed, in the log file we can see that the connection pool is filled at each request until it reaches the maximum (20, see the error above) : </p>
  
  <pre><code>[2017/05/11 10:06:48] [http-bio-0.0.0.0-20443-exec-4] DEBUG (LogicalConnectionImpl.java:226) org.hibernate.engine.jdbc.internal.LogicalConnectionImpl - Obtaining JDBC connection
  [2017/05/11 10:06:48] [http-bio-0.0.0.0-20443-exec-4] DEBUG (BasicResourcePool.java:587) com.mchange.v2.resourcepool.BasicResourcePool - acquire test -- pool size: 16; target_pool_size: 16; desired target? 17
  [2017/05/11 10:06:48] [http-bio-0.0.0.0-20443-exec-4] DEBUG (BasicResourcePool.java:450) com.mchange.v2.resourcepool.BasicResourcePool - incremented pending_acquires: 1
  [2017/05/11 10:06:48] [http-bio-0.0.0.0-20443-exec-4] DEBUG (BasicResourcePool.java:1788) com.mchange.v2.resourcepool.BasicResourcePool - Starting acquisition series. Incremented pending_acquires [1],  attempts_remaining: 30
  [2017/05/11 10:06:48] [http-bio-0.0.0.0-20443-exec-4] DEBUG (ThreadPoolAsynchronousRunner.java:236) com.mchange.v2.async.ThreadPoolAsynchronousRunner - com.mchange.v2.async.ThreadPoolAsynchronousRunner@67c8303a: Adding task to queue -- com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask@232613e3
  [2017/05/11 10:06:48] [http-bio-0.0.0.0-20443-exec-4] DEBUG (BasicResourcePool.java:1390) com.mchange.v2.resourcepool.BasicResourcePool - awaitAvailable(): com.mchange.v2.c3p0.impl.NewPooledConnection@547a79cf
  [2017/05/11 10:06:48] [http-bio-0.0.0.0-20443-exec-4] DEBUG (BasicResourcePool.java:1747) com.mchange.v2.resourcepool.BasicResourcePool - trace com.mchange.v2.resourcepool.BasicResourcePool@240ab5e6 [managed: 16, unused: 0, excluded: 0] (e.g. com.mchange.v2.c3p0.impl.NewPooledConnection@547a79cf)
  [2017/05/11 10:06:48] [C3P0PooledConnectionPoolManager[identityToken-&gt;2v3o059n1wfndya61hxar|3b29a008]-HelperThread-#1] DEBUG (GooGooStatementCache.java:333) com.mchange.v2.c3p0.stmt.GooGooStatementCache - checkinAll(): com.mchange.v2.c3p0.stmt.GlobalMaxOnlyStatementCache stats -- total size: 45; checked out: 0; num connections: 16; num keys: 45
  [2017/05/11 10:06:48] [C3P0PooledConnectionPoolManager[identityToken-&gt;2v3o059n1wfndya61hxar|3b29a008]-HelperThread-#1] DEBUG (C3P0PooledConnectionPool.java:283) com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool - com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager@58b73780.acquireResource() returning. 
  [2017/05/11 10:06:48] [C3P0PooledConnectionPoolManager[identityToken-&gt;2v3o059n1wfndya61hxar|3b29a008]-HelperThread-#1] DEBUG (BasicResourcePool.java:1747) com.mchange.v2.resourcepool.BasicResourcePool - trace com.mchange.v2.resourcepool.BasicResourcePool@240ab5e6 [managed: 17, unused: 1, excluded: 0] (e.g. com.mchange.v2.c3p0.impl.NewPooledConnection@547a79cf)
  [2017/05/11 10:06:48] [C3P0PooledConnectionPoolManager[identityToken-&gt;2v3o059n1wfndya61hxar|3b29a008]-HelperThread-#1] DEBUG (BasicResourcePool.java:471) com.mchange.v2.resourcepool.BasicResourcePool - decremented pending_acquires: 0
  [2017/05/11 10:06:48] [C3P0PooledConnectionPoolManager[identityToken-&gt;2v3o059n1wfndya61hxar|3b29a008]-HelperThread-#1] DEBUG (BasicResourcePool.java:1825) com.mchange.v2.resourcepool.BasicResourcePool - Acquisition series terminated successfully. Decremented pending_acquires [0],  attempts_remaining: 30
  [2017/05/11 10:06:48] [http-bio-0.0.0.0-20443-exec-4] DEBUG (BasicResourcePool.java:1747) com.mchange.v2.resourcepool.BasicResourcePool - trace com.mchange.v2.resourcepool.BasicResourcePool@240ab5e6 [managed: 17, unused: 0, excluded: 0] (e.g. com.mchange.v2.c3p0.impl.NewPooledConnection@547a79cf)
  [2017/05/11 10:06:48] [http-bio-0.0.0.0-20443-exec-4] DEBUG (LogicalConnectionImpl.java:232) org.hibernate.engine.jdbc.internal.LogicalConnectionImpl - Obtained JDBC connection
  </code></pre>
  
  <p>I have set up the following configuration for c3p0 : </p>
  
  <pre><code>hibernate.connection.release_mode=on_close
  hibernate.c3p0.validate=true
  hibernate.c3p0.min_size=5
  hibernate.c3p0.max_size=20
  hibernate.c3p0.timeout=1800
  hibernate.c3p0.max_statements=50
  hibernate.c3p0.preferredTestQuery=SELECT 1;
  hibernate.c3p0.idle_test_period=3000
  hibernate.c3p0.acquire_increment=1
  </code></pre>
  
  <p>And this is an example of how I make request :</p>
  
  <pre><code>public static void updateSignatureLogin(String login, int transactionId) {
      createEntityManagerFactory();
      EntityManager entityManager = entityManagerFactory.createEntityManager();
      entityManager.getTransaction().begin();
      IsignSignaturetraceEntity dbsignature = entityManager.find(IsignSignaturetraceEntity.class, transactionId);
      dbsignature.setLogin(login);
      entityManager.persist(dbsignature);
      entityManager.merge(dbsignature);
      entityManager.flush();
      entityManager.getTransaction().commit();
  }
  </code></pre>
  
  <p>What is the problem ? The way I manage connection/request in the code or configuration of c3p0 ?</p>
  
  <p>Thank you for your help.</p>