2017-08-11 71 views
0

我使用hibernate進行數據庫事務。我們的應用程序每次首次執行錯誤時都會發生錯誤,因爲我們每天執行的錯誤流量低於錯誤,並且發佈後我們會停止解決這些問題休眠配置:連接超時在應用程序結束後不活動

所以我的第一個疑問仍然是,我們以某種方式使用已經超時的空閒連接。我們總是可以使用hibernate.cfg.xml來處理這部分。

因此,我偶然發現了這樣做的各種方法,即通過在我們的休眠配置中添加以下參數中的任何一個,我們應該能夠解決相同的問題,但是他們中沒有一個解決我的目的,以避免閒置連接,我「連接超時」失敗在每一天的開始:

<property name="hibernate.c3p0.testConnectionOnCheckout">true</property> 
<property name="hibernate.c3p0.idle_test_period">30</property> 

我得到的錯誤是如下:

org.hibernate.exception.JDBCConnectionException: could not extract ResultSet 
    at org.hibernate.exception.internal.SQLStateConversionDelegate.convert(SQLStateConversionDelegate.java:132) ~[hibernate-core-4.2.1.Final.jar:4.2.1.Final] 
    at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49) ~[hibernate-core-4.2.1.Final.jar:4.2.1.Final] 
    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125) ~[hibernate-core-4.2.1.Final.jar:4.2.1.Final] 
    at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:110) ~[hibernate-core-4.2.1.Final.jar:4.2.1.Final] 
    at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:61) ~[hibernate-core-4.2.1.Final.jar:4.2.1.Final] 
    at org.hibernate.persister.entity.AbstractEntityPersister.getDatabaseSnapshot(AbstractEntityPersister.java:1520) ~[hibernate-core-4.2.1.Final.jar:4.2.1.Final] 
    at org.hibernate.engine.internal.StatefulPersistenceContext.getDatabaseSnapshot(StatefulPersistenceContext.java:316) ~[hibernate-core-4.2.1.Final.jar:4.2.1.Final] 
    at org.hibernate.engine.internal.ForeignKeys.isTransient(ForeignKeys.java:217) ~[hibernate-core-4.2.1.Final.jar:4.2.1.Final] 
    at org.hibernate.event.internal.AbstractSaveEventListener.getEntityState(AbstractSaveEventListener.java:497) ~[hibernate-core-4.2.1.Final.jar:4.2.1.Final] 
    at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.performSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:100) ~[hibernate-core-4.2.1.Final.jar:4.2.1.Final] 
    at org.hibernate.event.internal.DefaultSaveOrUpdateEventListener.onSaveOrUpdate(DefaultSaveOrUpdateEventListener.java:90) ~[hibernate-core-4.2.1.Final.jar:4.2.1.Final] 
    at org.hibernate.internal.SessionImpl.fireSaveOrUpdate(SessionImpl.java:735) ~[hibernate-core-4.2.1.Final.jar:4.2.1.Final] 
    at org.hibernate.internal.SessionImpl.saveOrUpdate(SessionImpl.java:727) ~[hibernate-core-4.2.1.Final.jar:4.2.1.Final] 
    at org.hibernate.internal.SessionImpl.saveOrUpdate(SessionImpl.java:723) ~[hibernate-core-4.2.1.Final.jar:4.2.1.Final] 
    at com.prod.ecmrs.dao.impl.AuditTrailDaoImpl.saveAuditTrail(AuditTrailDaoImpl.java:34) ~[classes:na] 
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.7.0_79] 
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[na:1.7.0_79] 
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.7.0_79] 
    at java.lang.reflect.Method.invoke(Method.java:606) ~[na:1.7.0_79] 
    at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317) [spring-aop-3.2.8.RELEASE.jar:3.2.8.RELEASE] 
    at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:183) [spring-aop-3.2.8.RELEASE.jar:3.2.8.RELEASE] 
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:150) [spring-aop-3.2.8.RELEASE.jar:3.2.8.RELEASE] 
    at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:96) [spring-tx-3.2.8.RELEASE.jar:3.2.8.RELEASE] 
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:260) [spring-tx-3.2.8.RELEASE.jar:3.2.8.RELEASE] 
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94) [spring-tx-3.2.8.RELEASE.jar:3.2.8.RELEASE] 
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172) [spring-aop-3.2.8.RELEASE.jar:3.2.8.RELEASE] 
    at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204) [spring-aop-3.2.8.RELEASE.jar:3.2.8.RELEASE] 
    at com.sun.proxy.$Proxy87.saveAuditTrail(Unknown Source) [na:na] 
    at com.prod.ecmrs.processor.ECMReportProcessor.process(ECMReportProcessor.java:107) [classes:na] 
    at org.apache.camel.processor.DelegateSyncProcessor.process(DelegateSyncProcessor.java:63) [camel-core-2.13.2.jar:2.13.2] 
    at org.apache.camel.management.InstrumentationProcessor.process(InstrumentationProcessor.java:72) [camel-core-2.13.2.jar:2.13.2] 
    at org.apache.camel.processor.RedeliveryErrorHandler.process(RedeliveryErrorHandler.java:398) [camel-core-2.13.2.jar:2.13.2] 
    at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191) [camel-core-2.13.2.jar:2.13.2] 
    at org.apache.camel.processor.CamelInternalProcessor.process(CamelInternalProcessor.java:191) [camel-core-2.13.2.jar:2.13.2] 
    at org.apache.camel.util.AsyncProcessorHelper.process(AsyncProcessorHelper.java:105) [camel-core-2.13.2.jar:2.13.2] 
    at org.apache.camel.processor.DelegateAsyncProcessor.process(DelegateAsyncProcessor.java:87) [camel-core-2.13.2.jar:2.13.2] 
    at org.apache.camel.component.jms.EndpointMessageListener.onMessage(EndpointMessageListener.java:103) [camel-jms-2.12.3.jar:2.12.3] 
    at org.springframework.jms.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:562) [spring-jms-3.2.5.RELEASE.jar:3.2.5.RELEASE] 
    at org.springframework.jms.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:500) [spring-jms-3.2.5.RELEASE.jar:3.2.5.RELEASE] 
    at org.springframework.jms.listener.AbstractMessageListenerContainer.doExecuteListener(AbstractMessageListenerContainer.java:468) [spring-jms-3.2.5.RELEASE.jar:3.2.5.RELEASE] 
    at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.doReceiveAndExecute(AbstractPollingMessageListenerContainer.java:325) [spring-jms-3.2.5.RELEASE.jar:3.2.5.RELEASE] 
    at org.springframework.jms.listener.AbstractPollingMessageListenerContainer.receiveAndExecute(AbstractPollingMessageListenerContainer.java:263) [spring-jms-3.2.5.RELEASE.jar:3.2.5.RELEASE] 
    at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.invokeListener(DefaultMessageListenerContainer.java:1103) [spring-jms-3.2.5.RELEASE.jar:3.2.5.RELEASE] 
    at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.executeOngoingLoop(DefaultMessageListenerContainer.java:1095) [spring-jms-3.2.5.RELEASE.jar:3.2.5.RELEASE] 
    at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:992) [spring-jms-3.2.5.RELEASE.jar:3.2.5.RELEASE] 
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [na:1.7.0_79] 
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [na:1.7.0_79] 
    at java.lang.Thread.run(Thread.java:745) [na:1.7.0_79] 
Caused by: java.sql.SQLRecoverableException: IO Error: Connection timed out 
    at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:874) ~[ojdbc6-11.2.0.jar:11.2.0.1.0] 
    at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1145) ~[ojdbc6-11.2.0.jar:11.2.0.1.0] 
    at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1267) ~[ojdbc6-11.2.0.jar:11.2.0.1.0] 
    at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3449) ~[ojdbc6-11.2.0.jar:11.2.0.1.0] 
    at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3493) ~[ojdbc6-11.2.0.jar:11.2.0.1.0] 
    at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeQuery(OraclePreparedStatementWrapper.java:1491) ~[ojdbc6-11.2.0.jar:11.2.0.1.0] 
    at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:96) ~[commons-dbcp-1.4.jar:1.4] 
    at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:96) ~[commons-dbcp-1.4.jar:1.4] 
    at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:56) ~[hibernate-core-4.2.1.Final.jar:4.2.1.Final] 
    ... 43 common frames omitted 
Caused by: java.net.SocketException: Connection timed out 
    at java.net.SocketInputStream.socketRead0(Native Method) ~[na:1.7.0_79] 
    at java.net.SocketInputStream.read(SocketInputStream.java:152) ~[na:1.7.0_79] 
    at java.net.SocketInputStream.read(SocketInputStream.java:122) ~[na:1.7.0_79] 
    at oracle.net.ns.Packet.receive(Packet.java:282) ~[ojdbc6-11.2.0.jar:11.2.0.1.0] 
    at oracle.net.ns.DataPacket.receive(DataPacket.java:103) ~[ojdbc6-11.2.0.jar:11.2.0.1.0] 
    at oracle.net.ns.NetInputStream.getNextPacket(NetInputStream.java:230) ~[ojdbc6-11.2.0.jar:11.2.0.1.0] 
    at oracle.net.ns.NetInputStream.read(NetInputStream.java:175) ~[ojdbc6-11.2.0.jar:11.2.0.1.0] 
    at oracle.net.ns.NetInputStream.read(NetInputStream.java:100) ~[ojdbc6-11.2.0.jar:11.2.0.1.0] 
    at oracle.net.ns.NetInputStream.read(NetInputStream.java:85) ~[ojdbc6-11.2.0.jar:11.2.0.1.0] 
    at oracle.jdbc.driver.T4CSocketInputStreamWrapper.readNextPacket(T4CSocketInputStreamWrapper.java:122) ~[ojdbc6-11.2.0.jar:11.2.0.1.0] 
    at oracle.jdbc.driver.T4CSocketInputStreamWrapper.read(T4CSocketInputStreamWrapper.java:78) ~[ojdbc6-11.2.0.jar:11.2.0.1.0] 
    at oracle.jdbc.driver.T4CMAREngine.unmarshalUB1(T4CMAREngine.java:1179) ~[ojdbc6-11.2.0.jar:11.2.0.1.0] 
    at oracle.jdbc.driver.T4CMAREngine.unmarshalSB1(T4CMAREngine.java:1155) ~[ojdbc6-11.2.0.jar:11.2.0.1.0] 
    at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:279) ~[ojdbc6-11.2.0.jar:11.2.0.1.0] 
    at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:186) ~[ojdbc6-11.2.0.jar:11.2.0.1.0] 
    at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:521) ~[ojdbc6-11.2.0.jar:11.2.0.1.0] 
    at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:205) ~[ojdbc6-11.2.0.jar:11.2.0.1.0] 
    at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:861) ~[ojdbc6-11.2.0.jar:11.2.0.1.0] 
    ... 51 common frames omitted 

我的hibernate.cfg.xml是如下:

<?xml version="1.0" encoding="utf-8"?> 
<!DOCTYPE hibernate-configuration PUBLIC 
"-//Hibernate/Hibernate Configuration DTD 3.0//EN" 
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd"> 
<hibernate-configuration> 
<session-factory> 
     <!-- <property name="hibernate.connection.driver_class">oracle.jdbc.driver.OracleDriver</property> 
     <property name="hibernate.connection.url">jdbc:oracle:thin:@127.0.0.1:1521:orcl</property> --> 
     <property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property> 
     <property name="hibernate.default_schema">ECMREPORT</property> 
     <property name="hibernate.c3p0.testConnectionOnCheckout">true</property> 
     <property name="hibernate.c3p0.timeout">600</property> 
     <property name="hibernate.c3p0.maxIdleTimeExcessConnections">20</property> 
     <property name="hibernate.c3p0.validate">false</property> 
     <property name="hibernate.c3p0.idle_test_period">30</property> 
     <property name="hibernate.c3p0.automaticTestTable">conTestTable</property> 
     <property name="show_sql">true</property> 
     <!-- <property name="hibernate.hbm2ddl.auto">update</property>--> 
     <mapping class="com.prod.ecmrs.dao.entity.AuditTrail"></mapping> 
     <mapping class="com.prod.ecmrs.dao.entity.ECMConfigDetail"></mapping> 
     <mapping class="com.prod.ecmrs.dao.entity.BSCSFUP"></mapping> 
     <mapping class="com.prod.ecmrs.dao.entity.BSCSRoaming"></mapping> 
     <mapping class="com.prod.ecmrs.dao.entity.BSCSRatePlan"></mapping> 
     <mapping class="com.prod.ecmrs.dao.entity.BSCSService"></mapping> 
     <mapping class="com.prod.ecmrs.dao.entity.OFSPlans"></mapping> 
     <mapping class="com.prod.ecmrs.dao.entity.OFSPacks"></mapping> 
     <mapping class="com.prod.ecmrs.dao.entity.CRMPlans"></mapping> 
     <mapping class="com.prod.ecmrs.dao.entity.CRMPacks"></mapping> 
     <mapping class="com.prod.ecmrs.dao.entity.ProjectPlan"></mapping> 
     <mapping class="com.prod.ecmrs.dao.entity.ProductionDumpReport"></mapping> 
     <mapping class="com.prod.ecmrs.dao.entity.RAITReportDump"></mapping> 
    </session-factory> 
</hibernate-configuration> 

回答

1

這是關於建立與數據庫的連接。您是否嘗試增加登錄超時時間?

<property name="hibernate.c3p0.timeout">180</property> 
+0

是的,我做了,我把它增加到600,如果你會看到我附加的休眠配置文件 –

+0

@Parul,你解決了這個問題嗎? – Losusovic

+0

這是一個系統問題。當我嘗試在其他服務器上已經存在的hibernate配置文件時,我沒有遇到任何其他問題。 –