我正在使用hibernate
和C3P0
,我的目标是测试select 1;
是否有效,我想在控制台中记录select 1
。我的控制台中有此日志,但没有执行select 1
:
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>
如果应用程序正常运行,则测试不会失败。 (您有testConnectionOnCheckout -> true
,因此如果测试失败,则您的应用程序将没有连接。)
但是,如果您使用的是最新的c3p0和较旧的(JDBC4或更高版本)的JDBC驱动程序,则可能会完全忽略首选的测试查询,而是依赖于为此目的而设计的Connection.isValid()
。
如果您将记录器com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool
设置为TRACE
或在您使用的任何日志记录库中的等效项,都可以获取c3p0测试的一些记录。不幸的是,它没有记录测试查询。