title: No operations allowed after connection closed
body: <p>I'm getting this error from a Java application:</p>
  
  <pre><code>com.mchange.v2.c3p0.impl.NewPooledConnection - [c3p0] Another 
  error has occurred [     
  com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: 
  No operations allowed after connection closed. ] which will not be 
  reported to listeners!
  </code></pre>
  
  <p>The Java code:</p>
  
  <pre><code>try {
      sessionFactory.beginTransaction();
      //...
      sessionFactory.commitTransaction();
  } catch (Exception e) {
      sessionFactory.rollbackTransaction();
      throw new RuntimeException(e);
  }
  </code></pre>
  
  <p>The session factory:</p>
  
  <pre><code>try {
      sessionFactory.beginTransaction();
      ...
      sessionFactory.commitTransaction();
  } catch (Exception e) {
      sessionFactory.rollbackTransaction();
      throw new RuntimeException(e);
  }
  
  public Transaction beginTransaction() throws HibernateException {
      try {
          return sessionFactory.getCurrentSession().beginTransaction();
      } catch (HibernateException hex) {
          LOG.error(String.format("Unable to start database transaction due to exception: %s.", ExceptionUtils.getRootCauseMessage(hex)));
          throw hex;
      }
  }
  
  public void commitTransaction() throws HibernateException {
      LOG.debug("Committing database transaction.");
      try {
          if (sessionFactory.getCurrentSession().getTransaction().isActive()) {
              sessionFactory.getCurrentSession().getTransaction().commit();
          } else {
              throw new HibernateException("Transaction is no longer Active.");
          }
      } catch (HibernateException hex) {
          LOG.error(String.format("Unable to commit due to exception: %s.", ExceptionUtils.getRootCauseMessage(hex)));
          throw hex;
      }
  }
  
  public void rollbackTransaction() throws HibernateException {
      LOG.debug("Trying to rollback database transaction after exception.");
      Session session = sessionFactory.getCurrentSession();
      try {
          if (session.getTransaction().isActive()) {
              session.getTransaction().rollback();
          } else {
              throw new HibernateException("Transaction is no longer Active.");
          }
      } catch (HibernateException hex) {
          LOG.error(String.format("Unable to rollback due to exception: %s.", ExceptionUtils.getRootCauseMessage(hex)));
          throw hex;
      } finally {
          if (session.isOpen()) {
              session.close();
          }
      }
  }
  </code></pre>
  
  <p>Hibernate and C3P0 settings:</p>
  
  <pre><code>&lt;prop key="hibernate.connection.provider_class"&gt;org.hibernate.connection.C3P0ConnectionProvider&lt;/prop&gt;
  &lt;prop key="hibernate.connection.driver_class"&gt;com.mysql.jdbc.Driver&lt;/prop&gt;
  
  &lt;prop key="hibernate.dialect"&gt;org.hibernate.dialect.MySQLDialect&lt;/prop&gt;
  &lt;prop key="hibernate.show_sql"&gt;false&lt;/prop&gt;
  &lt;prop key="hibernate.current_session_context_class"&gt;thread&lt;/prop&gt;
  &lt;prop key="hibernate.transaction.factory_class"&gt;org.hibernate.transaction.JDBCTransactionFactory&lt;/prop&gt;
  &lt;prop key="hibernate.jdbc.batch_size"&gt;20&lt;/prop&gt;
  &lt;prop key="hibernate.order_inserts"&gt;true&lt;/prop&gt;
  &lt;prop key="hibernate.order_updates"&gt;true&lt;/prop&gt;
  &lt;prop key="hibernate.c3p0.timeout"&gt;1800 &lt;!-- seconds --&gt;&lt;/prop&gt;
  &lt;prop key="hibernate.c3p0.min_size"&gt;4&lt;/prop&gt;
  &lt;prop key="hibernate.c3p0.max_size"&gt;35&lt;/prop&gt;
  &lt;prop key="hibernate.c3p0.idle_test_period"&gt;240 &lt;!-- seconds --&gt;&lt;/prop&gt;
  &lt;prop key="hibernate.c3p0.acquire_increment"&gt;4&lt;/prop&gt;
  &lt;prop key="hibernate.c3p0.max_statements"&gt;0&lt;/prop&gt;
  &lt;prop key="hibernate.c3p0.preferredTestQuery"&gt;SELECT 1&lt;/prop&gt;
  &lt;prop key="c3p0.testConnectionOnCheckout"&gt;true&lt;/prop&gt;
  &lt;prop key="hibernate.connection.oracle.jdbc.ReadTimeout"&gt;60000 &lt;!-- milliseconds --&gt;&lt;/prop&gt;
  </code></pre>
  
  <p>Not sure how the connection can be still in use and this error thrown.  What is causing this error?</p>