persistence.xml 中 jpa 的 C3p0 连接池不起作用?
在尝试按照我能找到的所有示例配置 c3p0 后,我仍然遇到 JDBC 超时问题。我正在使用 JPA、Hibernate、Tomcat、MySQL [AWS RDS]。这是 persistence.xml 的片段:
<property name="javax.persistence.jdbc.url"
value="jdbc:mysql://url..." />
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
<property name="connection.provider_class" value="org.hibernate.connection.C3P0ConnectionProvider"/>
<property name="hibernate.c3p0.acquire_increment" value="4" />
<property name="hibernate.c3p0.idle_test_period" value="3000" />
<property name="hibernate.c3p0.max_size" value="100" />
<property name="hibernate.c3p0.max_statements" value="15" />
<property name="hibernate.c3p0.min_size" value="5" />
<property name="hibernate.c3p0.timeout" value="100" />
以及错误日志:
09:18:51.776 WARN org.hibernate.util.JDBCExceptionReporter - SQL Error: 0, SQLState: 08S01
09:18:51.777 ERROR org.hibernate.util.JDBCExceptionReporter - The last packet successfully received from the server was 38,491,585 milliseconds ago. ...
I'm still getting JDBC timeouts after trying to configure c3p0 following all of the examples I could find. I'm using JPA, Hibernate, Tomcat, MySQL [AWS RDS]. Here's the snippet from persistence.xml:
<property name="javax.persistence.jdbc.url"
value="jdbc:mysql://url..." />
<property name="javax.persistence.jdbc.driver" value="com.mysql.jdbc.Driver" />
<property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
<property name="connection.provider_class" value="org.hibernate.connection.C3P0ConnectionProvider"/>
<property name="hibernate.c3p0.acquire_increment" value="4" />
<property name="hibernate.c3p0.idle_test_period" value="3000" />
<property name="hibernate.c3p0.max_size" value="100" />
<property name="hibernate.c3p0.max_statements" value="15" />
<property name="hibernate.c3p0.min_size" value="5" />
<property name="hibernate.c3p0.timeout" value="100" />
And the error log:
09:18:51.776 WARN org.hibernate.util.JDBCExceptionReporter - SQL Error: 0, SQLState: 08S01
09:18:51.777 ERROR org.hibernate.util.JDBCExceptionReporter - The last packet successfully received from the server was 38,491,585 milliseconds ago. ...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我从这个博客中找到了答案:
http://blog.hpxn.net/2009/02/05/using -c3p0-and-hibernate-3/
persistence.xml 中的属性是错误的,你应该以 hibernate 开头拼写它们:
然后,你会看到这个神话般的日志出现:
问候,
Stéphane(抱歉赏金)
I found the answer from this blog :
http://blog.hpxn.net/2009/02/05/using-c3p0-and-hibernate-3/
Properties in persistence.xml were just wrong, you should spell them beginning by hibernate :
And then, you will see this fabulous log appear :
Regards,
Stéphane (sorry for the bounty)
配置看起来没问题。激活日志记录并确保 C3P0 以适当的设置启动。
The configuration looks OK. Activate logging and make sure that C3P0 is starting with the appropriate settings.