Skip to Main Content

Java Database Connectivity (JDBC)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Problem with broken connections. Hibernate, C3P0, MySQL.

843859May 2 2008 — edited Nov 20 2014
There is a problem with Hibernate and DB connections on my website.
I use C3P0 to setup the connection pool and DB connections in the pool always break after some timeout.

For example, I visit my website and see the essage:
"org.hibernate.exception.JDBCConnectionException: could not execute query"
Then I reload the page and it is shown correctly. The same behavior is on other pages, some of them are shown correctly, others are not (until reloaded).
When I restart Tomcat the application is working correctly for some time.

I suspect that there are some errors in my config.

Here is the fragment of my "hibernate.cfg.xml":

<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost/prbase_ru</property>
<property name="connection.username">prbase</property>
<property name="connection.password">prssec</property>
<property name="connection.pool_size">0</property>
<property name="dialect">org.hibernate.dialect.MySQL5Dialect</property>
<property name="current_session_context_class">thread</property>
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
<property name="show_sql">true</property>

<property name="c3p0.max_size">5</property>
<property name="c3p0.min_size">1</property>
<property name="c3p0.timeout">600</property>
<property name="c3p0.max_statements">100</property>
<property name="c3p0.idle_test_period">50</property>
<property name="c3p0.acquire_increment">2</property>
<property name="c3p0.idleConnectionTestPeriod">50</property>
<property name="c3p0.testConnectionsOnCheckIn">1</property>
<property name="c3p0.automaticTestTable">c_test</property>

The test table "c_test" is created successfully but it seems to me that the connection testing does not function.
Is there some errors in this config?
How to make C3P0 correctly test and renew the connections?

Thanks in advance for any help, any really working samples, etc.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 14 2008
Added on May 2 2008
10 comments
1,080 views