title: Sometimes Hibernate can not get connection by C3P0
body: <p>I have a project use Struts2+hibernate3(c3p0),</p>
  
  <p>Following is my C3P0 configuration</p>
  
  <pre><code>    &lt;property name="hibernate.connection.provider_class"&gt;org.hibernate.connection.C3P0ConnectionProvider&lt;/property&gt;
      &lt;property name="hibernate.c3p0.acquire_increment"&gt;2&lt;/property&gt;
      &lt;property name="hibernate.c3p0.idle_test_period"&gt;15&lt;/property&gt;
      &lt;property name="hibernate.c3p0.max_idle_time"&gt;10&lt;/property&gt;
      &lt;property name="hibernate.c3p0.max_size"&gt;50&lt;/property&gt;
      &lt;property name="hibernate.c3p0.max_statements"&gt;100&lt;/property&gt;
      &lt;property name="hibernate.c3p0.min_size"&gt;20&lt;/property&gt;
      &lt;property name="hibernate.c3p0.timeout"&gt;10&lt;/property&gt;
      &lt;property name="hibernate.c3p0.validate"&gt;true&lt;/property&gt;
      &lt;property name="hibernate.c3p0.preferredTestQuery"&gt;select 1 from dual&lt;/property&gt;
      &lt;property name="automaticTestTable"&gt;Test&lt;/property&gt;
      &lt;!-- &lt;property name="hibernate.c3p0.testConnectionOnCheckout"&gt;true&lt;/property&gt; --&gt;
  
      &lt;property name="hibernate.connection.autoReconnect"&gt;true&lt;/property&gt;
      &lt;property name="hibernate.connection.autoReconnectForPools"&gt;true&lt;/property&gt;
      &lt;property name="hibernate.connection.is-connection-validation-required"&gt;true&lt;/property&gt;
  </code></pre>
  
  <p>My database is mysql and I can not config it (in cloud)</p>
  
  <p>My problem is some time I got following message </p>
  
  <pre><code>Caused by: org.hibernate.exception.GenericJDBCException: Cannot open connection
  at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:126)
  at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:114)
  at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
  at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:52)
  at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:449)
  at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:167)
  at org.hibernate.jdbc.JDBCContext.connection(JDBCContext.java:142)
  at org.hibernate.transaction.JDBCTransaction.begin(JDBCTransaction.java:85)
  at org.hibernate.impl.SessionImpl.beginTransaction(SessionImpl.java:1354)
  at com.rh.ws.getAllMessageAction.getAllMessage(getAllMessageAction.java:42)
  ... 86 more
  Caused by: java.sql.SQLException: Connections could not be acquired from the underlying database!
      at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:118)
      at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:690)
      at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:140)
      at org.hibernate.connection.C3P0ConnectionProvider.getConnection(C3P0ConnectionProvider.java:78)
      at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:446)
      ... 91 more
  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:1422)
      at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:606)
      at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:526)
      at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutAndMarkConnectionInUse(C3P0PooledConnectionPool.java:756)
      at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:683)
  </code></pre>
  
  <p>The wait_timeout is 30s in my database(mysql) and it's can not change.</p>
  
  <p>I try to set the max_idle_time to 20 and I discover it doesn't work.</p>
  
  <p>Do I need close the connection every time? or just close the session is fine?</p>