persistence.xml中jpa的C3p0连接池不工作? [英] C3p0 connection pooling for jpa in persistence.xml not working?

查看:217
本文介绍了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.drivervalue =com.mysql.jdbc.Driver/>
< property name =hibernate.dialectvalue =org.hibernate.dialect.MySQLDialect/>
< property name =connection.provider_classvalue =org.hibernate.connection.C3P0ConnectionProvider/>
< property name =hibernate.c3p0.acquire_incrementvalue =4/>
< property name =hibernate.c3p0.idle_test_periodvalue =3000/>
< property name =hibernate.c3p0.max_sizevalue =100/>
< property name =hibernate.c3p0.max_statementsvalue =15/>
< property name =hibernate.c3p0.min_sizevalue =5/>
< property name =hibernate.c3p0.timeoutvalue =100/>

以及错误日志:

  09:18:51.776 WARN org.hibernate.util.JDBCExceptionReporter  -  SQL错误:0,SQLState:08S01 
09:18:51.777错误org.hibernate.util.JDBCExceptionReporter - 最后从服务器成功收到的数据包是38,491,585毫秒前。 ...


解决方案

我从这个博客找到答案:
http://blog.hpxn.net/2009/02 / 05 / using-c3p0-and-hibernate-3 /



persistence.xml中的属性错了,你应该用hibernate开始拼写它们:

 < persistence xmlns =http://java.sun.com/xml/ns/persistence
xmlns :xsi =http://www.w3.org/2001/XMLSchema-instance
xsi:schemaLocation =http://java.sun.com/xml/ns/persistence http:// java。 sun.com/xml/ns/persistence/persistence_1_0.xsd
version =1.0>
< persistence-unit name =mypersistenceunitname>
<属性>
< property name =hibernate.connection.driver_classvalue =com.mysql.jdbc.Driver/>
< property name =hibernate.dialectvalue =org.hibernate.dialect.MySQLDialect/>
< property name =hibernate.hbm2ddl.autovalue =create-drop/>

<! - 重要 - >
< property name =hibernate.connection.provider_class
value =org.hibernate.connection.C3P0ConnectionProvider/>

< property name =hibernate.c3p0.max_sizevalue =100/>
< property name =hibernate.c3p0.min_sizevalue =0/>
< property name =hibernate.c3p0.acquire_incrementvalue =1/>
< property name =hibernate.c3p0.idle_test_periodvalue =300/>
< property name =hibernate.c3p0.max_statementsvalue =0/>
< property name =hibernate.c3p0.timeoutvalue =100/>
< / properties>
< / persistence-unit>
< /余辉>

然后,您会看到这个美妙的日志出现:

  2011-08-15 08:58:33 com.mchange.v2.c3p0.C3P0Registry banner 
INFO:Initializing c3p0-0.9.1 [built 16- January-2007 14:46:42;调试?真正; trace:10]
2011-08-15 08:58:33 com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource getPoolManager
INFO:初始化c3p0池... com.mchange.v2.c3p0。 PoolBackedDataSource @ f3a94e12 [connectionPoolDataSource - >

Stéphane(对于赏金感到抱歉)

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.  ...

解决方案

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 :

<persistence xmlns="http://java.sun.com/xml/ns/persistence"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://java.sun.com/xml/ns/persistence         http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
  version="1.0">
    <persistence-unit name="mypersistenceunitname">
      <properties>
        <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />
        <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
        <property name="hibernate.hbm2ddl.auto" value="create-drop" />

        <!-- Important -->
        <property name="hibernate.connection.provider_class"
          value="org.hibernate.connection.C3P0ConnectionProvider" />

        <property name="hibernate.c3p0.max_size" value="100" />
        <property name="hibernate.c3p0.min_size" value="0" />
        <property name="hibernate.c3p0.acquire_increment" value="1" />
        <property name="hibernate.c3p0.idle_test_period" value="300" />
        <property name="hibernate.c3p0.max_statements" value="0" />
        <property name="hibernate.c3p0.timeout" value="100" />
      </properties>
    </persistence-unit>
</persistence>

And then, you will see this fabulous log appear :

2011-08-15 08:58:33 com.mchange.v2.c3p0.C3P0Registry banner
INFO: Initializing c3p0-0.9.1 [built 16-January-2007 14:46:42; debug? true; trace: 10]
2011-08-15 08:58:33 com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource getPoolManager
INFO: Initializing c3p0 pool... com.mchange.v2.c3p0.PoolBackedDataSource@f3a94e12 [     connectionPoolDataSource -> com.mchange.v2.c3p0.WrapperConnectionPoolDataSource@6297f706     ....

Regards, Stéphane (sorry for the bounty)

这篇关于persistence.xml中jpa的C3p0连接池不工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆