I'm working with hibernate
and C3P0
and my target is to test if select 1;
works or not, I want to log select 1
in my consol.
I had this log in my console but I didn't have select 1
executed:
2020-05-12 13:19:56,365 [http-nio-8080-exec-3] INFO (AbstractPoolBackedDataSource:462) - Initializing c3p0 pool... com.mchange.v2.c3p0.PoolBackedDataSource@fbfe8ac5 [ connectionPoolDataSource -> com.mchange.v2.c3p0.WrapperConnectionPoolDataSource@66460a64 [ acquireIncrement -> 1, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, debugUnreturnedConnectionStackTraces -> false, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, identityToken -> 1brb47waa2g67nfppp467|33e7dcd8, idleConnectionTestPeriod -> 60, initialPoolSize -> 3, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 100, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 50, maxStatements -> 100, maxStatementsPerConnection -> 0, minPoolSize -> 5, nestedDataSource -> com.mchange.v2.c3p0.DriverManagerDataSource@dd22c2a7 [ description -> null, driverClass -> null, factoryClassLocation -> null, identityToken -> 1brb47waa2g67nfppp467|7944ff00, jdbcUrl -> jdbc:mysql://192.168.1.13:3306/jbpm, properties -> {autoReconnect=true, is-connection-validation-required=true, user=******, password=******, autoReconnectForPools=true} ], preferredTestQuery -> select 1;, propertyCycle -> 0, testConnectionOnCheckin -> false, testConnectionOnCheckout -> true, unreturnedConnectionTimeout -> 0, usesTraditionalReflectiveProxies -> false; userOverrides: {} ], dataSourceName -> null, factoryClassLocation -> null, identityToken -> 1brb47waa2g67nfppp467|6f2545f6, numHelperThreads -> 3 ]
hibernate.cfg.xml
<property name="hibernate.c3p0.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
<property name="hibernate.c3p0.acquire_increment">1</property>
<property name="hibernate.c3p0.idle_test_period">1200</property>
<property name="hibernate.c3p0.max_size">50</property>
<property name="hibernate.c3p0.max_statements">100</property>
<property name="hibernate.c3p0.min_size">5</property>
<property name="hibernate.c3p0.timeout">1800</property>
<property name="hibernate.c3p0.preferredTestQuery">select 1;</property>
If the application is working, the tests aren't failing. (You have testConnectionOnCheckout -> true
, so your application would not have Connections if tests were failing.)
However, if you are using a recent c3p0 and a not-ancient (JDBC4 or newer) JDBC driver, you might leave the preferred test query out altogether, and rely upon Connection.isValid()
which is designed for the purpose.
You can get some logging of c3p0's tests if you set logger com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool
to TRACE
or equivalent in whatever logging library you are using. Unfortunately, it does not log the test query.