java - 保存时 hibernate 超时

标签 java mysql hibernate

我有一个使用 MySql 保存到表中的应用程序(该表有 2 个 JSON 字段,其中一个可以接收大输入)。在生产中我时不时地遇到以下错误:

SqlExceptionHelper - The last packet successfully received from the server was 71,290,382 milliseconds ago.
The last packet sent successfully to the server was 71,290,384 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.

我不明白为什么会发生这种情况,因为我在本地从未遇到过这个问题。这是我目前的配置:

cfg.setProperty("hibernate.c3p0.min_size", "5")
                .setProperty("hibernate.c3p0.max_size", "20")
                .setProperty("hibernate.c3p0.timeout", "30000")
                .setProperty("hibernate.c3p0.max_statements", "50")
                .setProperty("hibernate.c3p0.idle_test_period", "3000")
                .setProperty("hibernate.connection.autoReconnect", "true")
                .setProperty("hibernate.connection.autoReconnectForPools", "true");

我错过了什么吗?

最佳答案

不久前我们也遇到了同样的问题。我在历史记录中进行搜索,虽然您可以保留现有的值,但您需要添加以下值:<property name="connection.is-connection-validation-required">true</property> 。这对我们的工件起到了作用,但您需要检查您的情况,因为您可能有一些其他设置。

作为旁注,我认为应该是:

.setProperty("connection.autoReconnect", "true")
.setProperty("connection.autoReconnectForPools", "true");
<小时/>

我们还有一个c3p0.properties文件:

c3p0.preferredTestQuery=select 1 from dual
c3p0.maxConnectionAge=3600
c3p0.testConnectionOnCheckin=false
c3p0.testConnectionOnCheckout=true
c3p0.acquireRetryDelay=1500
c3p0.acquireRetryAttempts=15
c3p0.breakAfterAcquireFailure=false
c3p0.idleConnectionTestPeriod=200

关注testConnectionOnCheckout特别是。

关于java - 保存时 hibernate 超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50548358/

相关文章:

java - 我无法让一对一关系和继承在 Hibernate 中同时工作

java - 在 Gradle 中创建多个 sourceSet

java - 防止 Textview android 中的负数 - 代码

java - 如何在 Apache Ignite 中使用带外键的 Write-behind

java - Hibernate 和 Spring 3 不保存

java - hibernate.hbm2ddl.auto =create(不创建表)

java - Log4j 2 记录输出消息以及文​​件编号的链接

php - Cron 作业无法正常工作;是什么错误还是其他方法?

php - 使用 fetchColumn 显示记录数

java - 在循环中运行 nativeQuery 不会返回正确的数据