我正在使用一个简单的java应用程序来操作浏览器中的表记录。我用hibernate来进行DAO调用。该应用程序在正常使用情况下正常工但是,当应用程序空闲1到2天时,会发生以下异常。
引起:java.sql.SQLException:IO 错误:连接重置
使用c3p0后,时间延长至10天。但我希望应用程序一直在运行。
我一直在使用Linux服务器。 JDK 1.5。 Tomcat服务器6。
我的Hibernate配置,
JDBC:神谕:薄:@ something.com:1789:patentmd oracle.jdbc.driver.OracleDriver
<property name="hibernate.connection.username">something</property>
<property name="hibernate.connection.password">something</property>
<property name="hibernate.dialect">org.hibernate.dialect.Oracle10gDialect</property>
<property name="hibernate.show_sql">true</property>
<!-- <property name="hibernate.current_session_context_class">thread</property> -->
<property name="c3p0.acquire_increment">1</property>
<property name="c3p0.idle_test_period">30</property>
<property name="c3p0.max_size">5</property>
<property name="c3p0.min_size">2</property>
<property name="c3p0.max_statements">5</property>
<property name="c3p0.timeout">180</property>
<!-- Mapping Resources. One entry should exist for each table -->
<mapping resource="com/hibernate/pojo/clientgrp/ClientGroup.hbm.xml"/>
<mapping resource="com/hibernate/pojo/applepub/Apple_Pub.hbm.xml"/>
<mapping resource="com/hibernate/pojo/prspub/Prs_Pub.hbm.xml"/>
</session-factory>
完整堆栈跟踪,
$$$$$$$$$$ sessionfactory is not null
Connection : true
Hibernate: select clientgrou0_.MGR_PRS_ID as MGR1_0_, clientgrou0_.MGR_PRS_NAME as MGR2_0_, clientgrou0_.MGR_CLIENT_GROUP as
MGR3_0_, clientgrou0_.UPDATE_DT as UPDATE4_0_, clientgrou0_.CREATE_DT as CREATE5_0_, clientgrou0_.DEPT_NM as DEPT6_0_ from
CLIENTGROUPS clientgrou0_
############ ClientGroupDAO.getAll() , hibernate exception org.hibernate.exception.JDBCConnectionException: could not execu
te query
ClientGroupTableHandler.getAllRecords() $$$$$$$$ exception occured 6org.hibernate.HibernateException: org.hibernate.excepti
on.JDBCConnectionException: could not execute query
ClientGroupTableHandler.Main() $$$$$$$$ exception occured 1java.lang.Exception: org.hibernate.HibernateException: org.hiber
nate.exception.JDBCConnectionException: could not execute query
java.lang.Exception: org.hibernate.HibernateException: org.hibernate.exception.JDBCConnectionException: could not execute qu
ery
at com.web.servlets.ClientGroupTableHandler.getAllRecords(ClientGroupTableHandler.java:294)
at com.web.servlets.ClientGroupTableHandler.Main(ClientGroupTableHandler.java:76)
at com.web.servlets.ClientGroupTableHandler.doPost(ClientGroupTableHandler.java:56)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:619)
Caused by: org.hibernate.HibernateException: org.hibernate.exception.JDBCConnectionException: could not execute query
at com.hibernate.dao.ClientGroupDAO.getAll(ClientGroupDAO.java:76)
at com.web.servlets.ClientGroupTableHandler.getAllRecords(ClientGroupTableHandler.java:288)
... 16 more
Caused by: org.hibernate.exception.JDBCConnectionException: could not execute query
at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:99)
at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66)
at org.hibernate.loader.Loader.doList(Loader.java:2536)
at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2276)
at org.hibernate.loader.Loader.list(Loader.java:2271)
at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:452)
at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:363)
at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1268)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102)
at com.hibernate.dao.ClientGroupDAO.getAll(ClientGroupDAO.java:45)
... 17 more
Caused by: java.sql.SQLException: IO Error: Connection reset
at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:876)
at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1153)
at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1275)
at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3576)
at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3620)
at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeQuery(OraclePreparedStatementWrapper.java:1203)
at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208)
at org.hibernate.loader.Loader.getResultSet(Loader.java:1953)
at org.hibernate.loader.Loader.doQuery(Loader.java:802)
at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:274)
at org.hibernate.loader.Loader.doList(Loader.java:2533)
... 25 more
Caused by: java.net.SocketException: Connection reset
at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:96)
at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
at oracle.net.ns.DataPacket.send(DataPacket.java:199)
at oracle.net.ns.NetOutputStream.flush(NetOutputStream.java:211)
at oracle.net.ns.NetInputStream.getNextPacket(NetInputStream.java:227)
at oracle.net.ns.NetInputStream.read(NetInputStream.java:175)
at oracle.net.ns.NetInputStream.read(NetInputStream.java:100)
at oracle.net.ns.NetInputStream.read(NetInputStream.java:85)
at oracle.jdbc.driver.T4CSocketInputStreamWrapper.readNextPacket(T4CSocketInputStreamWrapper.java:123)
at oracle.jdbc.driver.T4CSocketInputStreamWrapper.read(T4CSocketInputStreamWrapper.java:79)
at oracle.jdbc.driver.T4CMAREngine.unmarshalUB1(T4CMAREngine.java:1122)
at oracle.jdbc.driver.T4CMAREngine.unmarshalSB1(T4CMAREngine.java:1099)
at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:288)
at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:191)
at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:523)
at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:207)
at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:863)
... 35 more
块引用
答案 0 :(得分:0)
看起来很奇怪,你是否以某种方式坚持陈旧的Hibernate Session?你应该总是得到一个全新的Hibernate Session并在之后发布它。
答案 1 :(得分:0)
底层连接陈旧。
正常的操作过程是让连接池在使用之前测试连接。
对于C3P0:
c3p0.testConnectionOnCheckout=true
c3p0.preferredTestQuery="select 1 from dual"
http://community.jboss.org/wiki/HowToConfigureTheC3P0ConnectionPool
另一个选项是将最小连接数设置为0,并确保将池配置为在达到数据库连接超时之前逐出未使用的连接。
答案 2 :(得分:0)
在hibernate配置文件中添加此属性。我希望它会起作用。
<property name="connection.provider_class">
org.hibernate.connection.C3P0ConnectionProvider
</property>