Announcement Announcement Module
Collapse
No announcement yet.
Unable to configure JPA to use C3p0 connection pool? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Unable to configure JPA to use C3p0 connection pool?

    Hi all,

    I am trying to get Spring/JPA configured to use Hibernate + c3p0 for connection pooling but I keep getting this exception: Caused by: com.mchange.v2.resourcepool.CannotAcquireResourceE xception: A ResourcePool could not acquire a resource from its primary factory or source.

    Hibernate 2.6.7
    Spring 3.0.3
    H2 Datasource. Here is the stack:

    Code:
    ervice,taskMetaDataDao,taskMetaDataService,taskLinkPreparator,configuration,magentoServiceLocator,magentoWebServiceClient,updateOrderStatusService,md5HashCheck]; root of factory hierarchy
    13:37:22,634  INFO LocalSessionFactoryBean:772 - Building new Hibernate SessionFactory
    13:37:23,325  INFO LocalContainerEntityManagerFactoryBean:221 - Building JPA container EntityManagerFactory for persistence unit 'PSC_PU'
    13:38:21,780 ERROR SchemaValidator:112 - could not get database metadata
    java.sql.SQLException: Connections could not be acquired from the underlying database!
    	at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:106)
    	at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:529)
    	at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:128)
    	at org.hibernate.connection.C3P0ConnectionProvider.getConnection(C3P0ConnectionProvider.java:56)
    	at org.hibernate.tool.hbm2ddl.SuppliedConnectionProviderConnectionHelper.prepare(SuppliedConnectionProviderConnectionHelper.java:27)
    	at org.hibernate.tool.hbm2ddl.SchemaValidator.validate(SchemaValidator.java:107)
    	at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:317)
    	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1300)
    	at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:859)
    	at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:669)
    	at org.hibernate.ejb.HibernatePersistence.createContainerEntityManagerFactory(HibernatePersistence.java:132)
    	at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:225)
    	at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:308)
    	at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1469)
    	at java.lang.Thread.run(Thread.java:680)
    Caused by: com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source.
    	at com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1319)
    	at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:557)
    	at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:477)
    	at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:525)
    	... 71 more
    13:38:21,780 ERROR SchemaValidator:112 - could not get database metadata
    java.sql.SQLException: Connections could not be acquired from the underlying database!
    	at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:106)
    	at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:529)
    	at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:128)
    	at org.hibernate.connection.C3P0ConnectionProvider.getConnection(C3P0ConnectionProvider.java:56)
    	at org.hibernate.tool.hbm2ddl.SuppliedConnectionProviderConnectionHelper.prepare(SuppliedConnectionProviderConnectionHelper.java:27)
    	at java.lang.Thread.run(Thread.java:680)
    Caused by: com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source.
    	at com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1319)
    	at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:557)
    	at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:477)
    	at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:525)
    	... 71 more
    13:38:21,782 ERROR SchemaValidator:120 - could not complete schema validation
    java.sql.SQLException: Connections could not be acquired from the underlying database!
    	at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:106)
    	at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:529)
    	at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:128)
    	at org.hibernate.connection.C3P0ConnectionProvider.getConnection(C3P0ConnectionProvider.java:56)
    	at org.hibernate.tool.hbm2ddl.SuppliedConnectionProviderConnectionHelper.prepare(SuppliedConnectionProviderConnectionHelper.java:27)
    	at org.hibernate.tool.hbm2ddl.SchemaValidator.validate(SchemaValidator.java:107)
    	at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:317)
    	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1300)
    	at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:859)
    	at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:669)
    	at java.lang.Thread.run(Thread.java:680)
    Caused by: com.mchange.v2.resourcepool.CannotAcquireResourceException: A ResourcePool could not acquire a resource from its primary factory or source.
    	at com.mchange.v2.resourcepool.BasicResourcePool.awaitAvailable(BasicResourcePool.java:1319)
    	at com.mchange.v2.resourcepool.BasicResourcePool.prelimCheckoutResource(BasicResourcePool.java:557)
    	at com.mchange.v2.resourcepool.BasicResourcePool.checkoutResource(BasicResourcePool.java:477)
    	at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:525)
    	... 71 more
    My configuration looks like this:

    Code:
    	<bean id="wf-dataSource" class="org.springframework.jdbc.datasource.SimpleDriverDataSource">
    		<property name="driverClass" value="${psc.db.driver}" />
    		<property name="url" value="${psc.db.url}" />
    		<property name="username" value="${psc.db.username}" />
    		<property name="password" value="${psc.db.password}" />
    	</bean>
    	<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    		<property name="jpaVendorAdapter">
    			<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter">
    				<property name="database" value="H2"/>
    				<property name="showSql" value="true"/>
    			</bean>
    		</property>	
    		<property name="dataSource" ref="wf-dataSource"/>
    		<property name="persistenceUnitName" value="PSC_PU" />
    		<property name="persistenceXmlLocation" value="classpath:META-INF/persistence.xml"></property>
    	</bean>
     	<bean id="transactionManager" class="org.springframework.orm.jpa.JpaTransactionManager">
            <property name="entityManagerFactory" ref="entityManagerFactory" />
        </bean>
    Persistence.xml

    Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <persistence 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"
    	version="1.0">
    	<persistence-unit name="PSC_PU" transaction-type="RESOURCE_LOCAL">
    	  	<provider>org.hibernate.ejb.HibernatePersistence</provider>
    	  	<!-- All JPA Managed beans backed by Hibernate must be listed here due to a Hibernate/JPA bug -->
    	  	<!-- <class>gov.psc.model.User</class>
    	  	<class>gov.psc.model.Role</class> -->
    	  	<class>gov.psc.bpmn.task.TaskMetaData</class>
    		<properties>
    			<!-- Only scan and detect annotated entities -->
    			<property name="hibernate.archive.autodetection" value="class, hbm" />
    			<!-- JDBC/Hibernate connection properties -->
    			<property name="hibernate.dialect" value="org.hibernate.dialect.H2Dialect" />
    			<!-- Set hibernate console formatting options -->
    			<property name="hibernate.show_sql" value="true" />
             	<property name="hibernate.hbm2ddl.auto" value="validate"/>
    			<property name="hibernate.format_sql" value="true" />
    			<property name="hibernate.use_sql_comments" value="false" />
    		</properties>
    	</persistence-unit>
    </persistence>
    This all works, but as soon as I add the C3p0 Connection pool manager to either the JPA properties or the persistence.xml I get the error above:
    Code:
    	<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
            ...
    	<property name="jpaProperties">
    	    <props>
    			<prop key="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</prop>
    		</props>
    	</property>		
          </bean>
    Any/all thoughts would be greatly appreciated!
    Last edited by griff; Oct 3rd, 2011, 01:54 PM. Reason: Uploaded entire error stack.
Working...
X