Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException:
The last packet successfully received from the server was 44,284,801 milliseconds ago.
The last packet sent successfully to the server was 44,284,810 milliseconds ago.
is longer than the server configured value of 'wait_timeout'.
You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts,
or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.
解决mysql的连接超时问题。
问题重现:
hibernate3.2的版本对c3p0的支持不好,在hibernate的配置文件中只支持配置c3p0的部分属性。
像如下这些就被支持
- automaticTestTable
- connectionTesterClassName
- idleConnectionTestPeriod(这个例外,对应hibernate.c3p0.idle_test_period)
- preferredTestQuery
- testConnectionOnCheckin
- testConnectionOnCheckout
1、让hibernate知道系统要使用c3p0数据源配置,随便在hibernate配置文件或hibernate.properties中配置一个c3p0属性,如:hibernate.c3p0.max_size=29
2、在hibernate配置文件的同级目录中新建一个文件:c3p0.properties文件,然后在这个文件中就可以直接使用c3p0的属性来配置了
如:
c3p0.maxPoolSize=30
c3p0.minPoolSize=1
c3p0.timeout=5000
c3p0.maxStatements=0
c3p0.acquireIncrement=2
c3p0.automaticTestTable=t_3p0_test_table
c3p0.testConnectionOnCheckin=true
c3p0.idleConnectionTestPeriod=301
c3p0.breakAfterAcquireFailure=true
#。。。。。。。。。。。。。
这样就能把c3p0的测试数据库连接的属性生效了,
如果使用spring,就不用这么配置了,spring能够支持这些属性的配置的。