How to solve CommunicationsException in Java while using Hibernate and MySQL
We aggregate and tag open source projects. We have collections of more than one million projects. Check out the projects section.
You might have faced CommunicationsException, basically timeout issue in Java while connecting to MySQL using Hibernate. The session would be timed out after certain period of time. You might be thinking that the your site or application is running without any issue but it would have stopped or crashed due to below exception.
The last packet successfully received from the server was 437,036,648 milliseconds ago. The last packet sent successfully to the server was 437,036,652 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.
To solve this issue, create a file c3p0.properties
and add the below properties. Place the file in the same path of Hibernate.cfg.xml. This file should be part of the jar.
Please post your feedback.
To find embedded technology information about MCU, IoT, AI etc Check out embedkari.com.