Hibernate Communications Link Error – C3P0,MySQL and broken pipe error

ok, I am in a mood to rant about my travails in this matter, But I am choosing to cut the long story short.

It is very easy to setup a project that runs on Hibernate with the help of the multitude of beginner tutorials that come up on google search.  And the settings and steps described there are good enough to carry you through your development schedule.  But rememeber your hibernate settings are not production ready, i.e. not fit to be used on a machine that will stay turned on 24X7 and run your application in its Webserver container.

The problem you will face is this – You will deploy the application , and it will work smoothly. But shortly after a few hours, the DB will get disconnected with the following exception – detailed exception details here – http://pastebin.com/4KujAmgD

Hibernate Settings to be used to overcome the Communications Link Error are these

<property name=”hibernate.dialect”>org.hibernate.dialect.MySQLDialect</property>
<propert name=”hibernate.connection.driver_class”>com.mysql.jdbc.Driver</property>
<property name=”hibernate.show_sql”>true</property>
<property name=”hibernate.connection.username”>xxxx</property>
<property name=”hibernate.connection.password”>xxxx</property>
<property name=”hibernate.connection.url”>http://localhost/MyDB</property&gt;
<property name=”hibernate.max_fetch_depth”>3</property>
<property name=”hibernate.connection.provider_class”>org.hibernate.connection.C3P0ConnectionProvider</property>
<property name=”hibernate.c3p0.acquire_increment”>2</property>
<property name=”hibernate.c3p0.idle_test_period”>300</property>
<property name=”hibernate.c3p0.timeout”>1800</property>
<property name=”hibernate.c3p0.max_size”>25</property>
<property name=”hibernate.c3p0.min_size” >3</property>
<property name=”hibernate.c3p0.max_statement”>0</property>
<property name=”hibernate.c3p0.preferredTestQuery”>select 1;</property>
<property name=”hibernate.c3p0.validate”>true</property>

BUT, if you use these settings, and deploy your app, It will surely not work. Particularly if you use Hibernate 3.  You have to do one more step –

Download the latest c3p0 tar.gz file from http://sourceforge.net/projects/c3p0/ Now put the c3p0-0.9.1.x.jar file into your Webcontents/WEB-INF folder.

Now when you deploy your application, it will work without failing. For explanations about what the above settings mean, refer to http://www.skill-guru.com/blog/2009/10/06/hibernate-tutorial-part-ii/

About vatsalad

Hi, I'm Vatsala
This entry was posted in Flex Deployment Problems, hibernate, How To.... Bookmark the permalink.

5 Responses to Hibernate Communications Link Error – C3P0,MySQL and broken pipe error

  1. Martin says:

    Hi vatsalad,

    Thanks for these information.

    I needed this rows in my hibernate.cfg.xml too


    I think the only row I really need is the first one.

    you have a error in these row:

    property not propert

  2. Karan Shergil says:

    I did not understand

  3. Natraj Kadur says:

    I have the same properties as yours. But I am still getting the error.

    I am using OpenJPA for JPA in my application.

    • vatsalad says:

      Hi Natraj, Just check the relevant configuration settings of all the items in your toolkit, i.e. your app, hibernate and that of your MySQL(i assume) installation. I am unable to give you a detailed answer as I am out of context with your app.

Comments are closed.