C3P0 Connection pool fails

Description

I am trying to use C3P0 connection pool in my persitence.xml file in wildfly 20 which uses hibernate 5.3.17

Connections in C3P0 fails with following error:

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 the error is that hibernate removes hibernate.connection.url and hibernate.connection.driver_class from properties when it detect a datasource configured. Eventhough I have not configured any datasource in my persistence.xml wildfly is substituting a default datasource and that is causing hibernate to remove the above properties and thus the failure occurs. My persistence.xml is:

Environment

None

Activity

Show:
Jasvant Singh
September 25, 2020, 5:45 AM

The reason for using C3P0 Connection pool is performance gain. We were using it with wildfly 10 for performance gain. Now I am migrating it to wildfly 20. Wildfly 20 comes with hibernate 5.3.17 which removes hibernate.connection.url and hibernate.connection.driver_class from properties when it detects a datasource. What is aim of removing these properties?

Sanne Grinovero
September 25, 2020, 10:21 AM

Ok, thanks for the context. I’m not sure why the properties are being removed, we’ll have a look.

I’m surprised though that C3P0 would perform better. Did you measure this accurately? I suppose that it’s possible in specific configuration and contexts, but just to let you know: in our test the WildFly datasource is generally better for performance; it’s also integrated with other subsystems (statistics, security, transactionmanager to mention a few), so I wonder if you’re seeing better performance because you don’t need such integrations (which you could also disable if that’s the case?) , or if you’re possibly running your system unintentionally without such useful aspects.

Jasvant Singh
September 25, 2020, 12:02 PM
Edited

org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl line 899 of hibernate 5.3.17 contains following code

Scott Marlow
September 25, 2020, 5:39 PM

With regard to WildFly 10, are you sure that the C3P0 connection pool was actually being used?

Is your application written to use Java EE features like EJB + JTA Transaction management? Or is your application not using those parts of WildFly?

Scott Marlow
September 29, 2020, 1:07 PM
Edited

As mentioned on the WildFly forum post, the workaround is setting the following hint for the WildFly JPA container to stop passing the datasource:

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

Assignee

Unassigned

Reporter

Jasvant Singh

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Worked in

4.3.11

Components

Affects versions

Priority

Major
Configure