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.



Bookmark and Share          3596



comments powered by Disqus


Related Articles

How to learn from open source projects

Students ask this question frequently steps or methodology to learn from open source projects. There is no single answer or steps available. I listed the steps which i follow and i hope this will help for few.

Read more

Advantages and Disadvantages of using Hibernate like ORM libraries

Traditionally Programmers used ODBC, JDBC, ADO etc to access database. Developers need to write SQL queries, process the result set and convert the data in the form of objects (Data model). I think most programmers would typically write a function to convert the object to query and result set to object. To overcome these difficulties, ORM provides a mechanism to directly use objects and interact with the database.

Read more

Open source is the backbone for Startups

Many startups are entering in to the business due to open source. Open source acts as a back bone / pillar for their business. It reduces the cost of production, Generates revenue from consulting and support. This article describes about the startups which flourished because of open source. Sun acquired MySQL for $1Bn is the biggest achievement for open source startups.

Read more

Top 15 Open source alternative to Microsoft products

Microsoft is monopoly in the commercial software. Here are 15 best alternatives to most popular and widely used Microsoft products.

Read more

Why require Searchengine? Why not use database for full text search in Enterprise application.

Most of the database has support of full text search, basically indexing and saarching. MySQL, Oracle and many more databases has in-built full text search. Then what is the need to go for external search engine like Lucene, Sphinx, Solr etc. Check out the advantage of using Searchengine.

Read more

Pros and Cons of GPL licenese

GPL is widely used and known license in Open Source community. Richard Stallman father of GNU is the man behind GPL. GPL gives freedom and not free software.

Read more

Is it good time to switch from MySQL and choose some other database?

Recently you might have seen many news that big organization like Redhat, Fedora, Wikipedia switched their database from MySQL. Now Google also going to join them. Why everyone want to move out of MySQL? It is once a popular and stable software. What is the reason behind and what are the possible alternatives.

Read more

How to contribute to open source

I could see many many students posting this question in many forums, I want to contribute to open source but How to contribute? There are many ways to do that. I have listed a few and I hope it might be useful.

Read more

An introduction to MongoDB

MongoDB is the most exciting SQL-free database currently available in the market. The new kid on the block, called MongoDB is a scalable, high-performance, open source, schema free and document oriented database that focuses on the ideas of NoSQL Approach. Written in C++, it has taken rapid strides since its emergence into the public sphere as a popular way to build your database applications.

Read more

Solr vs Elastic Search

Solr and Elastic Search are built on top of Lucene. Both are open source and both have extra features which makes programmer life easy. This article explains the difference and the best situation to choose between them.

Read more



We have collection of more than 1 Million open source products ranging from Enterprise product to small libraries in all platforms. We aggregate information from all open source repositories. Search and find the best for your needs. Check out open source project section.



Follow feeds Follow bestopensource on Twitter Follow bestopensource on Facebook


Open source products are scattered around the web. Please provide information about the open source projects you own / you use. Add Projects.

Do you provide Consulting, Training, Support for any open source products. Register your business

Tag Cloud >>