title: Hibernate resource pool closing too soon
body: <p>I am performing stress tests on our database, which is hibernate on MySQL.  I'm using the c3p0 connection pool with default configuration except for a maxpoolsize of 15.</p>
  
  <pre><code>interface EntityRepository extends JpaRepository&lt;Entity, UUID&gt; {}
  
  @Service
  public class EntityService {
  
      @Autowired
      EntityRepository er;
  
      @Transactional(propagation = Propagation.REQUIRED)
      public Entity addEntity(Entity r) {
          er.save(r);
      }
  }
  
  public class StressTest {
  
      @Autowired
      EntityService rs;
  
      @Test
      public void entityStressTest() {
          for(int i = 0; i &lt; 100; i++) {
              Thread t = new Thread(new Runnable() {
                  public void run() {
                      rs.addEntity(new Entity());
                  }
              }
              t.start();
          }
      }
  }
  </code></pre>
  
  <p>Each time I run this test I create 5-8 entities, and then I receive one of the following three log messages:</p>
  
  <p>[ERROR] 14:39:23,127 [Thread-20] SqlExceptionHelper - An SQLException was provoked by the following failure: com.mchange.v2.resourcepool.ResourcePoolException: Attempted to use a closed or broken resource pool</p>
  
  <p>[ INFO] 14:48:45,478 [Thread-11] JdbcTransaction - HHH000425: Could not close session; swallowing exception[org.hibernate.service.UnknownServiceException: Unknown service requested [org.hibernate.stat.spi.StatisticsImplementor]] as transaction completed</p>
  
  <p>[ INFO] 14:49:22,860 [Thread-18] BasicResourcePool - com.mchange.v2.resourcepool.BasicResourcePool@16f7ca -- an attempt to checkout a resource was interrupted, because the pool is now closed. [Thread: Thread-18]</p>
  
  <p>I am stumped as to what could be causing this</p>