2010-10-15 75 views
6

在嘗試配置c3p0後,我仍然收到了JDBC超時,下面列出了所有可以找到的示例。我正在使用JPA,Hibernate,Tomcat,MySQL [AWS RDS]。下面是從persistence.xml中的片段:persistence.xml中jpa的C3p0連接池不工作?

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

對我來說同樣的錯誤。我決定爲這個問題開一個獎金。 @Pascal Thivent的回答沒有幫助,我沒有記錄c3po(也啓用了登錄)。 – Snicolas 2011-08-15 12:54:03

回答

2

的配置看起來不錯。激活日誌記錄並確保C3P0以適當的設置開始。

 
2010-10-16 11:58:31,271 INFO [main] o.h.c.ConnectionProviderFactory [ConnectionProviderFactory.java:173] Initializing connection provider: org.hibernate.connection.C3P0ConnectionProvider 
... 
+0

記錄被激活(事實上,我使用jetty,一個網絡服務器,它記錄每一個)。我得到了非常相同的持久性文件,用於hibernate的c3po和c3po都是我的類路徑(web-inf/classes,並且所有內容都通過maven部署)。但我沒有得到有關c3po的日誌信息。請幫助 – Snicolas 2011-08-15 12:53:11

16

我發現從這個博客的答案:在persistence.xml中 http://blog.hpxn.net/2009/02/05/using-c3p0-and-hibernate-3/

屬性只是錯了,你應該拼他們開始由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> 

然後,你會看到這個神話般的日誌出現:

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... [email protected] [  connectionPoolDataSource -> [email protected]  .... 

Regards, Stéphane(抱歉的賞金)

+0

你能幫助嗎?https://stackoverflow.com/questions/47011116/the-last-packet-sent-successfully-to-the-server-was-70-400-003 -milliseconds股份公司 – Tony 2017-10-30 09:12:30