Sunday, March 29, 2009

Hibernate Exception - java.net.SocketException: Broken pipe

In my current project I am using Hibernate ORM model for java to mysql bridge. And after deploying the module in a test sever I got the exception "java.net.SocketException: Broken pipe".

I have found the possible reasons may be, 

1. I didn't set the connection timeout parameters for the connection pool
2. The main scenario is, hibernate connection pool keeps the opened connection for a long time and mysql closes it when its idle time reaches for the opened connection.
3. When hibernate trys to do something with this connection which is closed by mysql got the exception.

Possible solution is, try to define the idle timeout value for the connection in hibernate lower than the mysql system connection idle timeout. This is very easy in hibernate.cfg.xml file to define the connection pool parameters and a lot of web resources can be found by google how to do it. 

Thanks. Hope it will help you.

No comments: