Hibernate 對c3p0配置不支援導致的錯誤

來源:互聯網
上載者:User

標籤:java.net.sockettimeoutexception: read timed out   nested exception is org.hibernate.transactionexception: jdbc commit failed   jdbc   jdbc錯誤   

項目結構是:springmvc +hibernate+mysql,

資料庫連接池:C3P0

伺服器使用的是tomcat7

出現的狀況是:訪問的時候經常出現404錯誤

實驗的過程剛開始以為是資料庫版本的問題,但是用過了各個版本,包括作業系統用windows,linux都試過,錯誤是一樣的。

也試過網路上面講的改變mysql的設定檔,增加連線時間,但是錯誤依舊。

在和我們公司的汪總和程式員溝通之後,終於得到解決。

原因是

HIBERNATE的配置不一定能管理動C3P0

出現的錯誤提示:


HTTP Status 500 - Request processing failed; nested exception is org.springframework.orm.hibernate3.HibernateSystemException: JDBC commit failed; nested exception is org.hibernate.TransactionException: JDBC commit failed


type Exception report


message Request processing failed; nested exception is org.springframework.orm.hibernate3.HibernateSystemException: JDBC commit failed; nested exception is org.hibernate.TransactionException: JDBC commit failed


description The server encountered an internal error that prevented it from fulfilling this request.


exception


org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.orm.hibernate3.HibernateSystemException: JDBC commit failed; nested exception is org.hibernate.TransactionException: JDBC commit failed


org.springframework.orm.hibernate3.HibernateSystemException: JDBC commit failed; nested exception is org.hibernate.TransactionException: JDBC commit failed


com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed.


com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure


The last packet successfully received from the server was 149,464 milliseconds ago.  The last packet sent successfully to the server was 18,923 milliseconds ago.


java.net.SocketTimeoutException: Read timed out

解決問題的辦法是改變spring的設定檔applicationContext.xml,增加相關的配置

在<beans>標籤內加入下面相關的配置:


<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">

<property name="driverClass" value="${jdbc.driver}" />

<property name="jdbcUrl" value="${jdbc.url}" />

<property name="user" value="${jdbc.username}" />

<property name="password" value="${jdbc.password}" />

<property name="initialPoolSize" value="${connection_pools.initial_pool_size}" />

<property name="minPoolSize" value="${connection_pools.min_pool_size}" />

<property name="maxPoolSize" value="${connection_pools.max_pool_size}" />

<property name="maxIdleTime" value="${connection_pools.max_idle_time}" />

<property name="acquireIncrement" value="${connection_pools.acquire_increment}" />

<property name="checkoutTimeout" value="${connection_pools.checkout_timeout}" />

<property name="testConnectionOnCheckin" value="false"/>

             <property name="testConnectionOnCheckout" value="true"/>

             <property name="preferredTestQuery" value="SELECT 1"/>

</bean>

配置完重啟伺服器就可以了

本文出自 “7422562” 部落格,請務必保留此出處http://7432562.blog.51cto.com/7422562/1577594

Hibernate 對c3p0配置不支援導致的錯誤

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.