1、问题描述
hibernate+jpa+oracle+c3p0 出现错误 长时间不连接后,第一次连接数据库报错,再连接正常;
2016-12-29 13:36:09.328 [http-bio-8081-exec-7] ERROR o.h.e.j.s.sqlExceptionHelper - IO 错误: Software caused connection abort: recv Failed
2016-12-29 13:36:09.344 [http-bio-8081-exec-7] WARN c.m.v.c.i.NewPooledConnection - [c3p0] A PooledConnection that has already signalled a Connection error is still in use!
2016-12-29 13:36:09.344 [http-bio-8081-exec-7] WARN c.m.v.c.i.NewPooledConnection - [c3p0] Another error has occurred [ java.sql.sqlRecoverableException: 关闭的连接 ] which will not be reported to listeners!
java.sql.sqlRecoverableException: 关闭的连接
at oracle.jdbc.driver.PhysicalConnection.rollback(PhysicalConnection.java:3694) ~[ojdbc6-11.2.0.1.0.jar:11.2.0.1.0]
at com.mchange.v2.c3p0.impl.NewProxyConnection.rollback(NewProxyConnection.java:860) [c3p0-0.9.2.1.jar:0.9.2.1]
at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.doRollback(JdbcTransaction.java:163) [hibernate-core-4.3.8.Final.jar:4.3.8.Final]
at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.rollback(AbstractTransactionImpl.java:211) [hibernate-core-4.3.8.Final.jar:4.3.8.Final]
at org.hibernate.jpa.internal.TransactionImpl.rollback(TransactionImpl.java:108) [hibernate-entitymanager-4.3.8.Final.jar:4.3.8.Final]
at org.springframework.orm.jpa.JpaTransactionManager.doRollback(JpaTransactionManager.java:544) [spring-orm-4.2.5.RELEASE.jar:4.2.5.RELEASE]
at org.springframework.transaction.support.AbstractPlatformTransactionManager.processRollback(AbstractPlatformTransactionManager.java:853)
2、问题分析
一开始以为是c3p0的问题,后来改为ojdbc直接连接还是出错,排除这个错误。
再次调研,发现是oracle的bug。。。
3、解决方案
<!-- 数据库连接声明 --> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close"> <property name="driverClass" value="${jdbc.driver}" /> <property name="jdbcUrl" value="${jdbc.url}" /> <!-- 每60秒检查所有连接池中的空闲连接。Default: 0 --> <property name="idleConnectionTestPeriod" value="60" /> <!--如果设为true那么在取得连接的同时将校验连接的有效性。Default: false --> <property name="testConnectionOnCheckin" value="true" /> <!--c3p0将建一张名为Test的空表,并使用其自带的查询语句进行测试。如果定义了这个参数那么 属性preferredTestQuery将被忽略。你不能在这张Test表上进行任何操作,它将只供c3p0测试 使用。Default: null --> <property name="automaticTestTable" value="C3P0Test" /> <property name="properties"> <props> <prop key="user">${jdbc.user}</prop> <prop key="password">${jdbc.password}</prop> </props> </property> </bean>
c3p0会自动创建个C3P0Test给自己测试
参考文档:http://ryanxl.iteye.com/blog/1694741