Error while using C3P0 connection Pool in wildfly 20

31 views
Skip to first unread message

Jasvant Singh

unread,
Sep 25, 2020, 4:12:46 PM9/25/20
to WildFly

Hi,
I am getting following error while configuring C3P0 Connection pool in wildfly.

2020-09-24 12:01:20,344 WARN  [com.mchange.v2.resourcepool.BasicResourcePool] (C3P0PooledConnectionPoolManager[identityToken->1hge13bac1gxr25d15hy3l7|767aa393]-HelperThread-#0) com.mchange.v2.resourcepool.BasicR
esourcePool$ScatteredAcquireTask@84b4ffa -- Acquisition Attempt Failed!!! Clearing pending acquires. While trying to acquire a needed new resource, we failed to succeed more than the maximum number of allowed ac
quisition attempts (30). Last acquisition attempt exception: : java.lang.NullPointerException
        at org.postgresql.Driver.parseURL(Driver.java:547)
        at org.postgresql.Driver.acceptsURL(Driver.java:466)
        at java.sql.DriverManager.getDriver(DriverManager.java:299)
        at com.mchange.v2.c3p0.DriverManagerDataSource.driver(DriverManagerDataSource.java:285)
        at com.mchange.v2.c3p0.DriverManagerDataSource.getConnection(DriverManagerDataSource.java:175)
        at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:220)
        at com.mchange.v2.c3p0.WrapperConnectionPoolDataSource.getPooledConnection(WrapperConnectionPoolDataSource.java:206)
        at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.acquireResource(C3P0PooledConnectionPool.java:203)
        at com.mchange.v2.resourcepool.BasicResourcePool.doAcquire(BasicResourcePool.java:1176)
        at com.mchange.v2.resourcepool.BasicResourcePool.doAcquireAndDecrementPendingAcquiresWithinLockOnSuccess(BasicResourcePool.java:1163)
        at com.mchange.v2.resourcepool.BasicResourcePool.access$700(BasicResourcePool.java:44)
        at com.mchange.v2.resourcepool.BasicResourcePool$ScatteredAcquireTask.run(BasicResourcePool.java:1908)
        at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:696)

The reason of th error is that wildfly is substituting default datasource in my persistence unit. If hibernate detects a datasource in configuration then it removes hibernate.connection.url and hibernate.connection.driver_class properties and thus the null pointer exception occurs.

My persistence.xml file looks like this:
<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="MyApplication" transaction-type="JTA">
        <properties>
            <property name="jboss.as.jpa.providerModule" value="org.hibernate"/>
        </properties>
    <provider>org.hibernate.ejb.HibernatePersistence</provider>
      <properties>
        <property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
        <property name="hibernate.show_sql" value="false"/>
        <property name="hibernate.format_sql" value="false" />
        <property name="hibernate.transaction.jta.platform" value="org.hibernate.service.jta.platform.internal.JBossAppServerJtaPlatform"/>
        <property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
        <property name="hibernate.session_factory_name" value="java:/jboss/SessionFactory"/>
        <property name="hibernate.cache.use_query_cache" value="true"/>
        <property name="hibernate.cache.use_second_level_cache" value="true"/>
        <property name="hibernate.cache.infinispan.cachemanager" value="java:jboss/infinispan/container/hibernate"/>
        <property name="hibernate.current_session_context_class" value="jta" />

       <property name="hibernate.connection.provider_class" value="org.hibernate.service.jdbc.connections.internal.C3P0ConnectionProvider"/>
       <property name="hibernate.connection.driver_class" value="org.postgresql.Driver" />
       <property name="hibernate.connection.url" value="jdbc:postgresql://localhost:5432/mydb" />
       <property name="hibernate.connection.username" value="user" />
       <property name="hibernate.connection.password" value="password" />
       <property name="hibernate.c3p0.min_size" value="20"/>
       <property name="hibernate.c3p0.max_size" value="200"/>
       <property name="hibernate.c3p0.timeout" value="300"/>
       <property name="hibernate.c3p0.max_statements" value="50"/>
       <property name="hibernate.c3p0.idle_test_periods" value="3000"/>
       <property name="hibernate.c3p0.testConnectionOnCheckin" value="true"/>
       <property name="hibernate.c3p0.preferredTestQuery" value="SELECT 1;"/>
       <property name="hibernate.c3p0.autoCommitOnClose" value="true"/>

      </properties>
   </persistence-unit>
</persistence>

Thanks,
Jasvant

Scott Marlow

unread,
Sep 25, 2020, 4:17:43 PM9/25/20
to WildFly
Thanks for responding here.  I asked a question on https://hibernate.atlassian.net/browse/HHH-14226 but can discuss here also.

Basically I am wondering what types of applications might use cp30 on WildFly?  Is this an application that mostly uses WildFly as a Web container?  Or does the application also control JTA transactions via EJB + enlisting the (connection pooled) datasources into the the JTA transactions?

Thanks,
Scott

Scott Marlow

unread,
Sep 28, 2020, 12:54:38 PM9/28/20
to WildFly
Also you could try adding a persistence unit property:

 <property name="wildfly.jpa.allowdefaultdatasourceuse" value="false" />      

Let us know if that helps.

Scott

Jasvant Singh

unread,
Sep 29, 2020, 9:01:47 AM9/29/20
to Scott Marlow, WildFly
Thanks! It worked.

--
You received this message because you are subscribed to a topic in the Google Groups "WildFly" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/wildfly/LClEdVhGoio/unsubscribe.
To unsubscribe from this group and all its topics, send an email to wildfly+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/wildfly/0f984802-6174-4085-9dd1-92b22bfc48fcn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages