title: In Spring Boot, using c3p0 simultaneously with jdbcTemplate and Hibernate
body: <p>I have a SpringBoot app (1.3.2.RELEASE on Java 8) and it's using both Hibernate 4.3.11.Final and SQL calls via JDBC against Oracle JDBC driver 12.1.0.1. It's also using hibernate-c3p0 4.3.11.Final. JDBC calls are made against an autowired JdbcTemplate instance.</p>
  
  <p>In my pom, I also have dependencies for Oracle UCP and ONS. Here are the relevant pom entries:</p>
  
  <pre><code>    &lt;dependency&gt;
          &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
          &lt;artifactId&gt;hibernate-entitymanager&lt;/artifactId&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
          &lt;artifactId&gt;hibernate-core&lt;/artifactId&gt;
          &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;org.hibernate&lt;/groupId&gt;
          &lt;artifactId&gt;hibernate-c3p0&lt;/artifactId&gt;
          &lt;version&gt;4.3.11.Final&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;com.oracle&lt;/groupId&gt;
          &lt;artifactId&gt;ojdbc7&lt;/artifactId&gt;
          &lt;version&gt;12.1.0.1&lt;/version&gt;
      &lt;/dependency&gt;
  
      &lt;dependency&gt;
          &lt;groupId&gt;com.oracle&lt;/groupId&gt;
          &lt;artifactId&gt;ucp&lt;/artifactId&gt;
          &lt;version&gt;12.1.0.2&lt;/version&gt;
      &lt;/dependency&gt;
      &lt;dependency&gt;
          &lt;groupId&gt;com.oracle&lt;/groupId&gt;
          &lt;artifactId&gt;ons&lt;/artifactId&gt;
          &lt;version&gt;12.1.0.2&lt;/version&gt;
      &lt;/dependency&gt;
  </code></pre>
  
  <p>However, I can find no configuration for the Oracle UCP. Also, all the configuration for c3p0 appears to just apply to Hibernate. </p>
  
  <p>Here are the relevant application.properties file entries (there are no other properties files):</p>
  
  <pre><code># Properties for Hibernate and Oracle
  spring.datasource.driverClassName=oracle.jdbc.driver.OracleDriver
  spring.jpa.database-platform=org.hibernate.dialect.Oracle10gDialect
  spring.jpa.properties.hibernate.connection.driver_class = oracle.jdbc.driver.OracleDriver
  
  spring.datasource.url=jdbc:oracle:thin:@my-db-server:1523:me
  spring.datasource.username=myuser
  spring.datasource.password=mypass
  
  
  # Configure the C3P0 database connection pooling module
  spring.jpa.properties.hibernate.c3p0.max_size = 15
  spring.jpa.properties.hibernate.c3p0.min_size = 6
  spring.jpa.properties.hibernate.c3p0.timeout = 2500
  spring.jpa.properties.hibernate.c3p0.max_statements_per_connection = 10
  spring.jpa.properties.hibernate.c3p0.idle_test_period = 3000
  spring.jpa.properties.hibernate.c3p0.acquire_increment = 3
  spring.jpa.properties.hibernate.c3p0.validate = false
  spring.jpa.properties.hibernate.c3p0.numHelperThreads = 15
  
  spring.jpa.properties.hibernate.connection.provider_class = org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider
  spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.Oracle10gDialect
  
  spring.jpa.properties.hibernate.connection.url=jdbc:oracle:thin:@sea-db-server:1523:me
  spring.jpa.properties.hibernate.connection.username=myuser
  spring.jpa.properties.hibernate.connection.password=mypass
  </code></pre>
  
  <p>What I am trying to figure out is whether or not the JDBC calls made against the spring autowired JdbcTemplate are using the c3p0 connection pool or not, and also if the Oracle UCP is doing anything at all since it appears to have no configuration.</p>
  
  <p>I really need connection pooling for the JDBC calls. Right now, I'm running into an issue where the connections to Oracle get closed. We're not using Oracle RAC, so I don't need UCP and therefore could just use c3p0. </p>
  
  <p>If someone could help me understand what's happening now, or tell me what to check for, I would appreciate it. Also, assuming I'm right and the JDBC calls are not using a pool, what's the best way to fix that?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Based on the answer and comments below, I decided to remove c3p0 and use a pool that is natively supported in Spring. So I'll pull c3p0 out of the pom (along with oracle ucp and ons) and have what is below in the application.properties file.</p>
  
  <p>I am trying to make sure that (1) I have a connection pool that will manage reconnection to the database should a connection be lost and (2) that JDBC and Hibernate are using the same datasource. </p>
  
  <p>Did I get this right? </p>
  
  <pre><code>spring.datasource.url=jdbc:oracle:thin:@db-server:1523:mysvc
  spring.datasource.username=myuser
  spring.datasource.password=mypass
  
  spring.datasource.max-active=50
  spring.datasource.initial-size=5
  spring.datasource.max-idle=10
  spring.datasource.min-idle=5
  spring.datasource.test-while-idle=true
  spring.datasource.test-on-borrow=true
  spring.datasource.validation-query=SELECT 1 FROM DUAL
  spring.datasource.time-between-eviction-runs-millis=5000
  spring.datasource.min-evictable-idle-time-millis=60000
  </code></pre>