Hibernate timeout when saving Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Hibernate timeout when saving without wasting too much if your time.

The question is published on by Tutorial Guruji team.

I have an app that uses MySql to save into a table (This table has 2 JSON fields and one of the can receive a large input). Every now and then in production I’m having the getting the following error:

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.

I’m not understanding why this happens, since localy I never faced this issue. This is the configuration I currently have:

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");

Am I missing something?.


We had the same issue a while back. I was searching in the history and while you can keep the values that you have, you would need to add this one: <property name="connection.is-connection-validation-required">true</property>. That did the trick for our artifact, but you would need to check in your case since you may have some other settings.

As a side note, I believe it should be:

.setProperty("connection.autoReconnect", "true")
.setProperty("connection.autoReconnectForPools", "true");

We also had a c3p0.properties file:

c3p0.preferredTestQuery=select 1 from dual

Pay attention to testConnectionOnCheckout in particular.

We are here to answer your question about Hibernate timeout when saving - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji