Hibernate C3P0 Connection Pool Config Changes

Posted Jan 31, 2010 // 2 comments
Jed:

Recently I had to debug yet another occurrence of the infamous "java.net.SocketException: Broken pipe" issue with Hibernate and MySQL. This application uses Hibernate 3.3.2 GA with C3P0 0.9.1.2. Our pool configuration has been working for years, and although I had recently deployed a new feature that forks Java processes for large-scale asychronous reporting (another story...), I was pretty certain that was not the culprit. I have encountered this a few times over the past several years and had always attributed it to long periods of inactivity coupled with incorrect connection pool configuration, but this time I was hesitant to fool with the configuration since it had been working fine for years.

But since I now have multiple processes hitting the database I couldn't rule out a connection leak somewhere, so I started debugging. There are a couple of C3P0 properties that can be used for debugging connection leaks and other bad-client behavior: debugUnreturnedConnectionStackTraces and unreturnedConnectionTimeout.

So I figured I'd need to turn up the C3P0 logging to make sure I knew where to find the output that setting these properties may produce. When I didn't see any output from C3P0, I set the log level for Hibernate to make sure my Log4J config changes were picked up. As I scanned the output from Hibernate I noticed that Hibernate was not using C3P0 at all, but its own rudimentary connection pool instead. Puzzling, since my Hibernate configuration includes the C3P0 properties that according to the Hibernate documentation should cause Hibernate to use C3P0.

Apparently not... you now have to explicitly configure Hibernate to use C3P0 by setting hibernate.connection.provider_class=org.hibernate.connection.C3P0ConnectionProvider. That will get you back in business as far as Hibernate and C3P0 is concerned. I'm not sure exactly when this "feature' appeared... but if you upgrade Hibernate and suddenly see odd behavior like broken pipe errors from applications that previously worked fine, check your Hibernate configuration and make sure you are using the connection pool you think you are.

About Jed

Senior Software Engineer Jed Prentice brings more than 15 years of experience developing business applications to Phase2 when he works on our client projects. He is an expert in the field of object-oriented software development, and he ...

more >

Read Jed's Blog

Comments

by Infos (not verified) on Tue, 06/15/2010 - 02:44

Hibernate with c3p0 is slow

Hi,

I have a problem with hibernate and c3p0. If I use c3p0 (hibernate.connection.provider_class=org.hibernate.connection.C3P0ConnectionProvider) then db queries are slower than without using c3p0. Any hint where the problem could be ?

by kiran (not verified) on Tue, 06/15/2010 - 03:34

hi Jed, I'm using the

hi Jed,

I'm using the WAS(websphere application server) Connection pooling.

how to work with EJB + Hibernate + WAS Connection pooling

any help on this... plz help me

and also couple of doubts

1. how hibernate performance is compare to JDBC. 2. which one is best HQl or stored procedures.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
  • Allowed HTML tags: <a> <strong> <code> <p> <img> <ul> <ol> <li> <h2> <h3> <h4> <b> <u> <i>
  • You may insert videos with [video:URL]

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.