title: Database connection exception using Spring, Hibernate, JPA e C3P0
body: <p>I'm trying to configure my app to use C3P0 datasource (I can't use the datasource provided by the container). </p>
  
  <p>But, when my app is starting, an exception has occurred:</p>
  
  <p><strong>The user must supply a JDBC connection</strong></p>
  
  <p>Bellow is my config files:</p>
  
  <p>spring-config.xml:</p>
  
  <pre><code>&lt;bean id="pum" class="org.springframework.orm.jpa.persistenceunit.DefaultPersistenceUnitManager"&gt;
      &lt;property name="persistenceXmlLocations"&gt;
          &lt;list&gt;
              &lt;value&gt;classpath*:META-INF/persistence.xml&lt;/value&gt;
          &lt;/list&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  
  &lt;bean id="pooledDataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"
      destroy-method="close"&gt;
      &lt;property name="driverClass" value="oracle.jdbc.driver.OracleDriver" /&gt;
      &lt;property name="jdbcUrl" value="jdbc:oracle:thin:@host:1521:db" /&gt;
      &lt;property name="user" value="dbuser" /&gt;
      &lt;property name="password" value="passwd" /&gt;
      &lt;property name="minPoolSize" value="5" /&gt;
      &lt;property name="maxPoolSize" value="10" /&gt;
      &lt;property name="maxStatements" value="0" /&gt;
  &lt;/bean&gt;
  
  &lt;bean id="entityManagerFactory"
      class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"&gt;
      &lt;property name="persistenceUnitManager" ref="pum" /&gt;
      &lt;property name="dataSource" ref="pooledDataSource" /&gt;
      &lt;property name="jpaVendorAdapter"&gt;
          &lt;bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/&gt;
      &lt;/property&gt;
  &lt;/bean&gt;
  
  &lt;bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager"&gt;
      &lt;property name="entityManagerFactory" ref="entityManagerFactory" /&gt;
  &lt;/bean&gt;
  
  &lt;tx:annotation-driven transaction-manager="transactionManager" /&gt;
  </code></pre>
  
  <p>persistence.xml:</p>
  
  <pre><code>&lt;persistence version="1.0"
  xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"&gt;
  
  &lt;persistence-unit name="AppPU" transaction-type="RESOURCE_LOCAL"&gt;
  
      &lt;properties&gt;
  
          &lt;property name="hibernate.dialect" value="org.hibernate.dialect.Oracle10gDialect" /&gt;            
          &lt;property name="hibernate.show_sql" value="false" /&gt;
          &lt;property name="hibernate.jdbc.batch_size" value="50" /&gt;
  
          &lt;property name="hibernate.archive.autodetection" value="class"/&gt;    
          &lt;property name="hibernate.cache.region.factory_class" value="net.sf.ehcache.hibernate.EhCacheRegionFactory" /&gt;
          &lt;property name="hibernate.cache.use_query_cache" value="true" /&gt;
          &lt;property name="hibernate.cache.use_second_level_cache" value="true" /&gt;
  
      &lt;/properties&gt;
  
  &lt;/persistence-unit&gt; 
  
  &lt;/persistence&gt;
  </code></pre>
  
  <p>Exception:</p>
  
  <pre><code>java.lang.UnsupportedOperationException: The user must supply a JDBC connection
  at org.hibernate.connection.UserSuppliedConnectionProvider.getConnection(UserSuppliedConnectionProvider.java:54)
  at org.hibernate.jdbc.ConnectionManager.openConnection(ConnectionManager.java:446)
  at org.hibernate.jdbc.ConnectionManager.getConnection(ConnectionManager.java:167)
  at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:161)
  at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1573)
  at org.hibernate.loader.Loader.doQuery(Loader.java:696)
  at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259)
  at org.hibernate.loader.Loader.doList(Loader.java:2228)
  at org.hibernate.loader.Loader.listUsingQueryCache(Loader.java:2157)
  at org.hibernate.loader.Loader.list(Loader.java:2117)
  at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:401)
  at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:361)
  at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196)
  at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1148)
  at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
  at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:67)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
  at java.lang.reflect.Method.invoke(Method.java:597)
  at org.springframework.orm.jpa.SharedEntityManagerCreator$DeferredQueryInvocationHandler.invoke(SharedEntityManagerCreator.java:310)
  at $Proxy286.getResultList(Unknown Source)
  at com.embraer.core.jpa.DaoSupport.execQueryIndexedParameters(DaoSupport.java:327)
  at com.embraer.core.jpa.DaoSupport.findByNamedQuery(DaoSupport.java:280)
  at com.embraer.core.jpa.DaoSupport.findAll(DaoSupport.java:132)
  at br.com.embraer.aheadpro.dao.imp.ConfigDAOImpl.findAll(ConfigDAOImpl.java:41)
  at br.com.embraer.aheadpro.dao.ConfigRepoDAO.getAll(ConfigRepoDAO.java:35)
  at br.com.embraer.aheadpro.service.ConfigService.refresh(ConfigService.java:27)
  at br.com.embraer.aheadpro.service.ConfigService.getConfig(ConfigService.java:35)
  at br.com.embraer.aheadpro.service.EmailService.init(EmailService.java:81)
  at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
  at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
  at java.lang.reflect.Method.invoke(Method.java:597)
  at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:340)
  at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:293)
  at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:130)
  ... 91 more
  </code></pre>
  
  <p>Thanks everybody!</p>