title: c3p0 Connection Pool not closing connections
body: <p>I have a Using c3p0 0.9.1.2 , hibernate 3.2.1.ga and spring 2.5.5. The problem is the database connection doesn't close itself.  Here are the logs :</p>
  
  <blockquote>
    <p>[22 mars 2012 12:29:56,091] DEBUG com.mchange.v2.resourcepool.BasicResourcePool ["http-apr-8080"-exec-4] acquire test -- pool is already maxed out. [managed: 20; max: 20]
    [22 mars 2012 12:29:56,091] DEBUG com.mchange.v2.resourcepool.BasicResourcePool ["http-apr-8080"-exec-4] awaitAvailable(): com.mchange.v2.c3p0.impl.NewPooledConnection@15cc604
    [22 mars 2012 12:29:56,091] DEBUG com.mchange.v2.resourcepool.BasicResourcePool ["http-apr-8080"-exec-4] trace com.mchange.v2.resourcepool.BasicResourcePool@6b0524 [managed: 20, unused: 0, excluded: 0] (e.g. com.mchange.v2.c3p0.impl.NewPooledConnection@15cc604)</p>
  </blockquote>
  
  <p>Here's the datasource configuration :</p>
  
  <p>
  </p>
  
  <p></p>
  
  <pre><code>&lt;!-- Local DataSource that works in any environment --&gt;
  &lt;bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"&gt;
      &lt;property name="driverClass" value="${database.driver}"/&gt;
      &lt;property name="jdbcUrl" value="${database.url}"/&gt;
      &lt;property name="user" value="${database.user}"/&gt;
      &lt;property name="password" value="${database.password}"/&gt;
      &lt;!--&lt;property name="connectionCustomizerClassName" value="org.xxx.webapp.common.persistence.WatchConnectionCustomizer"/&gt;--&gt;
      &lt;property name="maxStatements" value="500"/&gt;
      &lt;property name="maxIdleTime" value="1800"/&gt;
      &lt;property name="maxPoolSize" value="100"/&gt;
      &lt;property name="minPoolSize" value="2"/&gt;
      &lt;property name="initialPoolSize" value="2"/&gt;
      &lt;property name="acquireIncrement" value="3"/&gt;
      &lt;property name="idleConnectionTestPeriod" value="3000"/&gt;
  &lt;/bean&gt;
  
  
  
  &lt;bean id="sessionFactory"
      class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean" &gt;
      &lt;property name="hibernateProperties"&gt;
          &lt;props&gt;
              &lt;prop key="hibernate.dialect"&gt;${hibernate.dialect}&lt;/prop&gt;
              &lt;prop key="hibernate.show_sql"&gt;false&lt;/prop&gt;
              &lt;prop key="hibernate.hbm2ddl.auto"&gt;${hibernate.hbm2ddl.auto}&lt;/prop&gt;
              &lt;prop key="hibernate.connection.autocommit"&gt;${hibernate.connection.autocommit}&lt;/prop&gt;
              &lt;prop key="hibernate.transaction.auto_close_session"&gt;${hibernate.transaction.auto_close_session}&lt;/prop&gt;
              &lt;prop key="hibernate.connection.release_mode"&gt;${hibernate.connection.release_mode}&lt;/prop&gt;
              &lt;prop key="hibernate.bytecode.use_reflection_optimizer"&gt;${hibernate.bytecode.use_reflection_optimizer}&lt;/prop&gt;
              &lt;prop key="hibernate.cache.provider_class"&gt;org.hibernate.cache.EhCacheProvider&lt;/prop&gt;
              &lt;prop key="hibernate.cache.use_query_cache"&gt;true&lt;/prop&gt;
              &lt;prop key="hibernate.cache.use_second_level_cache"&gt;true&lt;/prop&gt;
              &lt;prop key="hibernate.cache.region.factory_class"&gt;net.sf.ehcache.hibernate.EhCacheRegionFactory&lt;/prop&gt;
          &lt;/props&gt;
      &lt;/property&gt;
  
   &lt;property name="annotatedClasses"&gt;
      &lt;list&gt;
          ...
     &lt;/list&gt;
      &lt;/property&gt;
  
     &lt;property name="dataSource"&gt;
      &lt;ref bean="dataSource" /&gt;
     &lt;/property&gt;
  
  
  &lt;/bean&gt;
  
  &lt;bean id="transactionManager"
      class="org.springframework.orm.hibernate3.HibernateTransactionManager"&gt;
      &lt;property name="sessionFactory"&gt;
          &lt;ref bean="sessionFactory" /&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  </code></pre>
  
  <p></p>
  
  <p>Here's our generic Dao</p>
  
  <pre><code>public class GenericDAO&lt;T, PK extends Serializable&gt; extends HibernateDaoSupport
      implements IGenericDAO&lt;T, PK&gt; {
  
  private Class&lt;T&gt; clazz;
  private Logger logger = Logger.getLogger(GenericDAO.class);
  private static Session session;
  
  public GenericDAO(Class&lt;T&gt; clazz) {
      this.clazz = clazz;
  }
  
  public void refresh(T instanceToRefresh) throws DataAccessException {
      getHibernateTemplate().refresh(instanceToRefresh);
      //getCurrentSession().refresh(instanceToRefresh);
  }
  
  public void saveOrUpdate(T instanceToSaveOrUpdate)
          throws DataAccessException {
      //getCurrentSession().saveOrUpdate(instanceToSaveOrUpdate);
      getHibernateTemplate().saveOrUpdate(instanceToSaveOrUpdate);
  }
  
  public void persist(T instanceToPersist) throws DataAccessException {
      getHibernateTemplate().persist(instanceToPersist);
      //getCurrentSession().persist(instanceToPersist);
  }
  
  @SuppressWarnings("unchecked")
  public T merge(T instanceToMerge) throws DataAccessException {
      T instanceMerged = (T) getHibernateTemplate().merge(instanceToMerge);
      //T instanceMerged = (T) getCurrentSession().merge(instanceToMerge);
      return instanceMerged;
  }
  
  @SuppressWarnings("unchecked")
  public PK save(T newInstance) throws DataAccessException {
      return (PK) getHibernateTemplate().save(newInstance);
      //return (PK) getCurrentSession().save(newInstance);
  }
  
  public void delete(T persistentObject) throws DataAccessException {
      getHibernateTemplate().delete(persistentObject);
      //getCurrentSession().delete(persistentObject);
  }
  
  @SuppressWarnings("unchecked")
  public T load(PK id) {
      return (T) getHibernateTemplate().get(clazz, id);
      //return (T) getCurrentSession().get(clazz, id);
  }
  
  public void update(T transientObject) throws DataAccessException {
      //getCurrentSession().update(transientObject);
      getHibernateTemplate().update(transientObject);
  }
  
  @SuppressWarnings("unchecked")
  public List&lt;T&gt; loadAll() throws DataAccessException {
      //Session session = this.getCurrentSession();
      //return session.createQuery("from " + clazz.getName()).list();
      return getHibernateTemplate().loadAll(clazz);
  }
  }
  </code></pre>
  
  <p>Thanks in advance.</p>