How to solve CommunicationsException in Java while using Hibernate and MySQL
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.
com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: 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.
c3p0.idleConnectionTestPeriod=100
c3p0.preferredTestQuery=SELECT 1
c3p0.testConnectionOnCheckin=true
c3p0.testConnectionOnCheckout=false
c3p0.debugUnreturnedConnectionStackTraces=true
com.mchange.v2.log.MLog=com.mchange.v2.log.log4j.Log4jMLog
Please post your feedback.
comments powered by Disqus
Related Articles
Open Source Technology Stack used in Opentaps ERP
opentaps Open Source ERP + CRM, is a fully integrated application suite that supports eCommerce, Customer Relationship Management, Warehouse and Inventory Management, Supply Chain Management, and Financial Management to Business Intelligence and mobility integration out-of-the-box. This article discusses about the open source software used to build Opentaps ERP.
Zimbra - Enterprise Email Server Stack
Zimbra is a Enterprise messaging and collaboration software. It is a good alternative to Microsoft Exchange server. Zimbra is a Email Server but they have not written anything related to SMTP server, rather they have integrated well know open source email server in to its package. Zimbra is a system of well connected / integrated multiple open source software which delivers enterprise quality to it. This article explains most important components which helps to build the enterprise product.
Open Source products used in Facebook
Facebook a leading social networking website predominantly uses open source technologies to build its application. Here is the list of open source products used and contributed by Facebook.
Simple Mail Stack for Linux Hosted Environment
Email is the primary way of communication. Small organization which hosts their website / any other application from a third party hosting service providers may require this email stack.
Open Source Technology Stack used in Magnolia CMS
Magnolia CMS is one among popular java based CMS. It has support of CMS, DMS, Wiki, Forum and lot more features. This article discusses about the open source software used to build Magnolia CMS.
Open source projects used to in Wikipedia
Wikipedia is a multilingual, collaboratively edited encyclopedia. It is one of the busiest site in the world. It has more than 8 million articles and accessed by millions of users around the world. This article briefly discuss about the open source software used in Wikipedia.
Open source products used in Twitter
Twitter uses many open source products and also contributes most of the code to open source. Here is the list of open source products used by Twitter. This list does not include the projects sponsored by twitter.
Open source projects used in LinkedIn
LinkedIn is a social network for professionals. LinkedIn handles millions of searches as well as hundreds of thousands of updates daily. They sponsored many projects to open source. Here are the list of open source products used by LinkedIn.