随机获取JDBCConnectionException

时间:2013-09-14 12:28:20

标签: java spring hibernate c3p0

在我的网络应用中,我经常遇到异常

org.hibernate.util.JDBCExceptionReporter: SQL Error: 17002, SQLState: 08006
        14 Sep 2013 12:19:10,927 [ERROR] org.hibernate.util.JDBCExceptionReporter: IO Error: Connection reset
        14 Sep 2013 12:19:10,927 [ERROR]  could not load an entity: [EntityName]
    nested exception is org.hibernate.exception.JDBCConnectionException: could not load an entity: [EntityName]

...

14 Sep 2013 12:19:10,930 [WARN]  (com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread-#0) com.mchange.v1.db.sql.StatementUtils: Statement close FAILED.
java.sql.SQLRecoverableException: Closed Connection
    at oracle.jdbc.driver.PhysicalConnection.needLine(PhysicalConnection.java:5389)
    at oracle.jdbc.driver.OracleStatement.closeOrCache(OracleStatement.java:1578)
    at oracle.jdbc.driver.OracleStatement.close(OracleStatement.java:1563)
    at oracle.jdbc.driver.OracleStatementWrapper.close(OracleStatementWrapper.java:94)
    at oracle.jdbc.driver.OraclePreparedStatementWrapper.close(OraclePreparedStatementWrapper.java:80)
    at com.mchange.v1.db.sql.StatementUtils.attemptClose(StatementUtils.java:41)
    at com.mchange.v2.c3p0.stmt.GooGooStatementCache.synchronousDestroyStatement(GooGooStatementCache.java:413)
    at com.mchange.v2.c3p0.stmt.GooGooStatementCache.closeAll(GooGooStatementCache.java:351)
    at com.mchange.v2.c3p0.impl.NewPooledConnection.closeAllCachedStatements(NewPooledConnection.java:673)
    at com.mchange.v2.c3p0.impl.NewPooledConnection.close(NewPooledConnection.java:543)
    at com.mchange.v2.c3p0.impl.NewPooledConnection.close(NewPooledConnection.java:234)
    at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool$1PooledConnectionResourcePoolManager.destroyResource(C3P0PooledConnectionPool.java:470)
    at com.mchange.v2.resourcepool.BasicResourcePool$1DestroyResourceTask.run(BasicResourcePool.java:964)
    at com.mchange.v2.async.ThreadPoolAsynchronousRunner$PoolThread.run(ThreadPoolAsynchronousRunner.java:547)

我尝试更改C3P0配置,但没有帮助

这是我目前的配置:

checkoutTimeout     10000   
idleConnectionTestPeriod        0
initialPoolSize     10  
maxIdleTime     28800   
maxPoolSize     20  
minPoolSize     8   
numHelperThreads        5
testConnectionOnCheckin     true

相关守则: 这是对HibernateTemplate的get方法的简单调用

Object result = getHibernateTemplate().get(entityClass, id);
return (T) result;

1 个答案:

答案 0 :(得分:2)

虽然听起来你已经尝试过一堆,如果你使用的是testConnectionOnCheckin,你应该将它与一个短的非零idleConnectionTestPeriod结合起来。为了提高性能,您还应该设置preferredTestQuery。

检查不可靠的连接测试是否是您的问题的最简单方法是从testConnectionOnCheckin切换到testConnectionOnCheckout(并添加preferredTestQuery以最小化性能影响)。如果这可以解决你的问题,那么你知道你需要的是良好的连接测试,你可以切换回来并使用idleConnectionTestPeriod的长度。如果testConnectionOnCheckout无法解决问题,那么它不太可能是连接测试问题。 testConnectionOnCheckout是一个非常可靠的设置。

http://www.mchange.com/projects/c3p0-0.9.5-pre4/#simple_advice_on_connection_testing http://www.mchange.com/projects/c3p0-0.9.5-pre4/#configuring_connection_testing