简体   繁体   English

Hibernate JDBCConnectionException-C3p0连接池

[英]Hibernate JDBCConnectionException - C3p0 connection pooling

We are using C3p0 connection pooling for our mysql db using HibernateORM. 我们正在使用HibernateORM为mysql数据库使用C3p0连接池。

Below are the settings in hibernate.cfg.xml 以下是hibernate.cfg.xml中的设置

<property name="hibernate.c3p0.acquire_increment">1</property>
<property name="hibernate.c3p0.idle_test_period">300</property>
<property name="hibernate.c3p0.maxConnectionAge">3600</property>
<property name="hibernate.c3p0.timeout">120</property>
<property name="hibernate.c3p0.max_size">300</property>
<property name="hibernate.c3p0.min_size">1</property>
<property name="hibernate.c3p0.max_statements">100</property>
<property name="hibernate.c3p0.preferredTestQuery">select 1;</property>

And for reconnection to the database after 28800 seconds we set the params - 为了在28800秒后重新连接到数据库,我们设置了参数-

c3p0.testConnectionOnCheckout=true

But we are facing hibernate exceptions. 但是我们正面临休眠异常。

So if I make a call to the DB now and wait for 8 hours ( or whatever amount of time I set the variable wait_timeout of my.cnf ), I get that exception if I make another call to the DB . 因此,如果现在立即调用数据库并等待8个小时(或设置my.cnf的变量wait_timeout的时间长短),那么如果再次调用该数据库,则会出现该异常。 stacktrace - 堆栈跟踪 -

org.hibernate.exception.JDBCConnectionException: could not execute query
        at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:99)
        at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
        at org.hibernate.loader.Loader.doList(Loader.java:2536)
        at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2276)
        at org.hibernate.loader.Loader.list(Loader.java:2271)
        at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:452)
        at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:363)
        at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196)
        at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1268)
        at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)

As a quick fix to the issue, we are restarting the app server every day morning. 为了快速解决此问题,我们每天早晨重新启动应用程序服务器。

Any help would be appreciated 任何帮助,将不胜感激

-- Thanks - 谢谢

if your config is what you think it is, there's no way these Exceptions come from stale Connections getting checked out after sitting idle and timing out in the pool. 如果您的配置是您的实际想法,则这些异常绝不会来自过时的连接,这些连接在闲置并在池中超时后被检出。 Connections expire after an hour no matter what, they are never idle more than about five minutes, they are tested on checkout. 一个小时后的连接无论如何都会过期,它们永远不会闲置超过五分钟,并且会在结帐时进行测试。

one of two things is going on: 发生两件事之一:

1) you don't have the configuration you think you have, something is going wrong in the middlewhere between your config and the c3p0 DataSource it intedns to configure. 1)您没有想要的配置,配置和它打算配置的c3p0数据源之间的中间出问题了。

fortunately, c3p0 DataSources dump their config at INFO level on initialization. 幸运的是,c3p0数据源在初始化时以INFO级别转储其配置。 check your logs, and verify that your pool has the config that you intend it to have. 检查您的日志,并验证您的池是否具有您想要的配置。

2) perhaps your app is holding Connections live outside of the pool, rather than checking them out for short periods and close()ing them, so that c3p0 ca do all that testing, expiring, etc. if your app holds Connections for so long that they time out, there is nothing c3p0 can do about it. 2)也许您的应用程序将Connections保留在池外,而不是将它们检查一小段时间并关闭()将它们关闭,以便c3p0 ca可以进行所有测试,到期等操作,如果您的应用程序长时间持有Connections他们超时了,c3p0对此无能为力。 c3p0 can help you test if this is what's going on, though. c3p0可以帮助您测试这是否正在发生。 try the config parameters unreturnedConnectionTimeout and debugUnreturnedConnectionStackTraces. 尝试使用配置参数unreturnedConnectionTimeout和debugUnreturnedConnectionStackTraces。 Use them together. 一起使用。 See 看到

http://www.mchange.com/projects/c3p0/#configuring_to_debug_and_workaround_broken_clients http://www.mchange.com/projects/c3p0/#configuring_to_debug_and_workaround_broken_clients

http://www.mchange.com/projects/c3p0/index.html#unreturnedConnectionTimeout http://www.mchange.com/projects/c3p0/index.html#unreturnedConnectionTimeout

http://www.mchange.com/projects/c3p0/index.html#debugUnreturnedConnectionStackTraces http://www.mchange.com/projects/c3p0/index.html#debugUnreturnedConnectionStackTraces

good luck! 祝好运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM