首页 > 代码库 > Hibernate 对c3p0配置不支持导致的错误

Hibernate 对c3p0配置不支持导致的错误

项目结构是: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="http://www.mamicode.com/${jdbc.driver}" />

<property name="jdbcUrl" value="http://www.mamicode.com/${jdbc.url}" />

<property name="user" value="http://www.mamicode.com/${jdbc.username}" />

<property name="password" value="http://www.mamicode.com/${jdbc.password}" />

<property name="initialPoolSize" value="http://www.mamicode.com/${connection_pools.initial_pool_size}" />

<property name="minPoolSize" value="http://www.mamicode.com/${connection_pools.min_pool_size}" />

<property name="maxPoolSize" value="http://www.mamicode.com/${connection_pools.max_pool_size}" />

<property name="maxIdleTime" value="http://www.mamicode.com/${connection_pools.max_idle_time}" />

<property name="acquireIncrement" value="http://www.mamicode.com/${connection_pools.acquire_increment}" />

<property name="checkoutTimeout" value="http://www.mamicode.com/${connection_pools.checkout_timeout}" />

<property name="testConnectionOnCheckin" value="http://www.mamicode.com/false"/>

             <property name="testConnectionOnCheckout" value="http://www.mamicode.com/true"/>

             <property name="preferredTestQuery" value="http://www.mamicode.com/SELECT 1"/>

</bean>

配置完重启服务器就可以了

本文出自 “7422562” 博客,请务必保留此出处http://7432562.blog.51cto.com/7422562/1577594

Hibernate 对c3p0配置不支持导致的错误