Database Connection to MySQL times out even after setting c3p0.testConnectionOnCheckout=true

岁酱吖の 提交于 2019-12-01 19:00:06

We started having the same "Communications Link" issue when we upgraded hibernate to 4.3.x using JPA and C3P0 for connection pooling.

It seems like this would be a connection pool issue since connections were being kept longer than the database wait_timeout (which was the default 8 hours) despite my C3P0 settings. However, I fixed the issue by changing the hibernate configuration in our persistence.xml with:

<property name="hibernate.connection.release_mode" value="after_transaction" />

It seems the default behavior in hibernate changed to not release the connection after transactions, so you have to explicitly set this mode if you're using pooling.

Add the below property in your hibernate config file. I hope it will work.

<property name="connection.provider_class">
  org.hibernate.connection.C3P0ConnectionProvider
</property>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!