Hibernate DB连接pooler c3p0有问题
自上一篇文章以来,所做的所有修改都有所建议,但这个问题仍然困扰着我。 这是我得到的错误:
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 44,499,102 milliseconds ago.
这是我的hibernate.cfg.xml
org.hibernate.connection.C3P0ConnectionProvider com.mysql.jdbc.Driver true true true 5 150 0 10 100 30 jdbc:mysql://!secret!autoReconnect=true !secret! !secret! <!-- 10 --> true org.hibernate.dialect.MySQLDialect update thread
和c3p0.properties
c3p0.preferredTestQuery=select 1 from dual c3p0.maxConnectionAge=3600 c3p0.testConnectionOnCheckin=true c3p0.testConnectionOnCheckout=true c3p0.acquireRetryDelay=1000 c3p0.acquireRetryAttempts=30 c3p0.breakAfterAcquireFailure=false c3p0.idleConnectionTestPeriod=100
至于我,你配置错误c3p0。
像c3p0.preferredTestQuery这样的属性必须位于类路径的c3p0.properties文件中(例如WEB-INF / classes)。
下面是我的适用于Oracle的c3p0.properties文件示例:
c3p0.preferredTestQuery=SELECT 1 from dual c3p0.maxConnectionAge=3600 c3p0.testConnectionOnCheckout=true c3p0.acquireRetryDelay=1000 c3p0.acquireRetryAttempts=30 c3p0.breakAfterAcquireFailure=false
另请参阅c3p0的官方文档。
请注意您正在使用的c3p0版本。 他们在c3p0 0.9的早期版本中有一个问题连接恢复。
似乎与数据库的连接已超时并已被数据库服务器终止。 您应该增加服务器等待的时间还是追加?autoReconnect = true到您的jdbc连接字符串。
我认为这篇文章可能有所帮助。 如果是这种情况,增加wait_timeout
的值只会推迟更多时间,而不是解决问题。
问题可能与此有关:
- 你打开一个hibernate会话
- 做一些比数据库的wait_timeout值花费更多时间的事情
- 您尝试使用此hibernate会话。 您将在此处评论的消息将显示
如果你有兴趣,我在这里记录了一个案例。
在根目录中的c3po.properties文件中输入以下行(1)。(您应该使用hibenate-c3po 3.6.10 final.jar)并在Hibeanate.cfg.xml中使用add(2)部分。
-
c3p0.testConnectionOnCheckout =真
-
100 30 10 10 1800 true