Τρίτη 23 Ιουνίου 2009

Hibernate and MySQL Database Connections

Hibernate and MySql connection lost

The hibernate when it is combined with MySQL commonly produces errors like Communication Link Failure or Last Packet sent to server XX ms ago or Socket Write Error etc. These problems often caused due to the timeout values of the MySQL server. When hibernate tries to re-connect to the Server there is no active connection to use and as a result an exception is thrown.

A common situation you may put your self in is to build a web app and everything work fine but when you return the following day you are facing exceptions. When you restart the server everything works fine again, but after a short amount of time you are facing the same exceptions.

There is a solution for this,

Change the hibernate's cfg.xml file and put the following lines,


<property name="connection.provider_class">
org.hibernate.connection.C3P0ConnectionProvider</property>

<property name="c3p0.max_size">100</property>
<property name="c3p0.idleConnectionTestPeriod">300</property>




Also do not forget to put c3p0-x.xx.x.jar into your classpath or server's lib folder.

Δεν υπάρχουν σχόλια:

Δημοσίευση σχολίου