Hibernate和c3p0:无法解释为什么客户端在一段时间后无法通信

时间:2014-01-20 11:37:55

标签: java hibernate c3p0

运行以下代码......

    Session session;

    try {
        session = sessionFactory.openSession();;

        // Query the DB for a list of sms to be sent
        Query query = session.createQuery("from Sdnchurch");            
        list = query.list();
    }
    catch(Exception e) {
        // Manage exception
    }
    finally {
        if (session != null) 
            session.close();
    }

...过了一段时间后,我得到以下异常:

failureorg.hibernate.exception.JDBCConnectionException: could not prepare statement

在我使用客户端的时间超过mySql中配置的WAIT_TIMEOUT时,会开始生成此异常。

这是我在hibernate.cfg.xml中的Hibernate的C3p0配置:

    <property name="connection.pool_size">1</property>
    <property name="dialect">org.hibernate.dialect.MySQLDialect</property>
    <property name="cache.provider_class">org.hibernate.connection.C3P0ConnectionProvider</property>
    <property name="show_sql">true</property>
    <property name="hbm2ddl.auto">update</property>

    <property name="hibernate.c3p0.min_size">50</property>
    <property name="hibernate.c3p0.max_size">200</property>
    <property name="hibernate.c3p0.acquire_increment">1</property>
    <property name="hibernate.c3p0.idle_test_period">3000</property>
    <property name="hibernate.c3p0.max_statements">50</property>
    <property name="hibernate.c3p0.timeout">7200</property>
    <property name="hibernate.c3p0.acquireRetryAttempts">0</property>
    <property name="hibernate.c3p0.maxStatementsPerConnection">10</property>
    <property name="hibernate.c3p0.numHelperThreads">10</property>
    <property name="hibernate.c3p0.idleConnectionTestPeriod">3600</property>
    <property name="hibernate.c3p0.preferredTestQuery">select 1</property>
    <property name="hibernate.c3p0.testConnectionOnCheckout">true</property>
    <property name="hibernate.c3p0.testConnectionOnCheckin">true</property>

如您所见,我也在测试连接。所以我无法真正看出出了什么问题。

我该如何解决这个问题?这是堆栈跟踪:

11:20:59,547 INFO  [stdout] (ajp--0.0.0.0-8009-1) Hibernate: select sdnchurc0_.CHURCH_ID as CHURCH1_0_, sdnchurc0_.CHURCH_NAME as CHURCH2_0_ from Msdchurch sdnchurc0_

11:20:59,549 WARN  [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (ajp--0.0.0.0-8009-1) SQL Error: 0, SQLState: 08003
11:20:59,549 ERROR [org.hibernate.engine.jdbc.spi.SqlExceptionHelper] (ajp--0.0.0.0-8009-1) No operations allowed after connection closed.Connection was implicitly closed by the driver.
11:20:59,549 INFO  [uk.co.nisma.sdn.dao.MsdchurchDaoImpl] (ajp--0.0.0.0-8009-1) Rolling back...
11:20:59,549 ERROR [stderr] (ajp--0.0.0.0-8009-1) uk.co.nisma.sdn.exception.MsdwardException: org.hibernate.exception.JDBCConnectionException: could not prepare statement

11:20:59,550 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at uk.co.nisma.sdn.dao.MsdchurchDaoImpl.getListHospitals(MsdchurchDaoImpl.java:53)

11:20:59,550 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at uk.co.nisma.sdn.WardDetailsImpl.getWardDetails(WardDetailsImpl.java:25)

11:20:59,551 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

11:20:59,551 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

11:20:59,551 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

11:20:59,551 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at java.lang.reflect.Method.invoke(Method.java:606)

11:20:59,551 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at org.jboss.ws.common.invocation.AbstractInvocationHandlerJSE.invoke(AbstractInvocationHandlerJSE.java:111)

11:20:59,552 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at org.jboss.wsf.stack.cxf.JBossWSInvoker._invokeInternal(JBossWSInvoker.java:181)

11:20:59,552 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at org.jboss.wsf.stack.cxf.JBossWSInvoker.invoke(JBossWSInvoker.java:127)

11:20:59,552 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at org.apache.cxf.interceptor.ServiceInvokerInterceptor$1.run(ServiceInvokerInterceptor.java:58)

11:20:59,552 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)

11:20:59,553 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)

11:20:59,553 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at java.util.concurrent.FutureTask.run(FutureTask.java:166)

11:20:59,553 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at org.apache.cxf.workqueue.SynchronousExecutor.execute(SynchronousExecutor.java:37)

11:20:59,553 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at org.apache.cxf.interceptor.ServiceInvokerInterceptor.handleMessage(ServiceInvokerInterceptor.java:106)

11:20:59,553 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:263)

11:20:59,554 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:121)

11:20:59,554 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at org.apache.cxf.transport.http.AbstractHTTPDestination.invoke(AbstractHTTPDestination.java:207)

11:20:59,554 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at org.jboss.wsf.stack.cxf.RequestHandlerImpl.handleHttpRequest(RequestHandlerImpl.java:91)

11:20:59,554 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at org.jboss.wsf.stack.cxf.transport.ServletHelper.callRequestHandler(ServletHelper.java:169)

11:20:59,555 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at org.jboss.wsf.stack.cxf.CXFServletExt.invoke(CXFServletExt.java:87)

11:20:59,555 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at org.apache.cxf.transport.servlet.AbstractHTTPServlet.handleRequest(AbstractHTTPServlet.java:185)

11:20:59,555 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at org.apache.cxf.transport.servlet.AbstractHTTPServlet.doPost(AbstractHTTPServlet.java:108)

11:20:59,555 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at javax.servlet.http.HttpServlet.service(HttpServlet.java:754)

11:20:59,556 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at org.jboss.wsf.stack.cxf.CXFServletExt.service(CXFServletExt.java:135)

11:20:59,556 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at org.jboss.wsf.spi.deployment.WSFServlet.service(WSFServlet.java:140)

11:20:59,556 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)

11:20:59,556 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329)

11:20:59,556 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248)

11:20:59,557 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275)

11:20:59,557 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)

11:20:59,557 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153)

11:20:59,557 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155)

11:20:59,558 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)

11:20:59,558 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)

11:20:59,558 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368)

11:20:59,558 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at org.apache.coyote.ajp.AjpProcessor.process(AjpProcessor.java:505)

11:20:59,559 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at org.apache.coyote.ajp.AjpProtocol$AjpConnectionHandler.process(AjpProtocol.java:445)

11:20:59,559 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930)

11:20:59,559 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at java.lang.Thread.run(Thread.java:724)

11:20:59,560 ERROR [stderr] (ajp--0.0.0.0-8009-1) Caused by: org.hibernate.exception.JDBCConnectionException: could not prepare statement

11:20:59,560 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at org.hibernate.exception.internal.SQLExceptionTypeDelegate.convert(SQLExceptionTypeDelegate.java:67)

11:20:59,560 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at org.hibernate.exception.internal.StandardSQLExceptionConverter.convert(StandardSQLExceptionConverter.java:49)

11:20:59,560 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at org.hibernate.engine.jdbc.spi.SqlExceptionHelper.convert(SqlExceptionHelper.java:125)

11:20:59,561 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:188)

11:20:59,561 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at org.hibernate.engine.jdbc.internal.StatementPreparerImpl.prepareQueryStatement(StatementPreparerImpl.java:159)

11:20:59,561 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1859)

11:20:59,561 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1836)

11:20:59,562 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1816)

11:20:59,562 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at org.hibernate.loader.Loader.doQuery(Loader.java:900)

11:20:59,562 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:342)

11:20:59,562 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at org.hibernate.loader.Loader.doList(Loader.java:2526)

11:20:59,562 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at org.hibernate.loader.Loader.doList(Loader.java:2512)

11:20:59,563 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2342)

11:20:59,563 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at org.hibernate.loader.Loader.list(Loader.java:2337)

11:20:59,563 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:495)

11:20:59,563 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at org.hibernate.hql.internal.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:356)

11:20:59,570 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at org.hibernate.engine.query.spi.HQLQueryPlan.performList(HQLQueryPlan.java:195)

11:20:59,570 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at org.hibernate.internal.SessionImpl.list(SessionImpl.java:1269)

11:20:59,570 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at org.hibernate.internal.QueryImpl.list(QueryImpl.java:101)

11:20:59,570 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at uk.co.nisma.sdn.dao.MsdchurchDaoImpl.getListHospitals(MsdchurchDaoImpl.java:47)

11:20:59,570 ERROR [stderr] (ajp--0.0.0.0-8009-1)   ... 39 more

11:20:59,571 ERROR [stderr] (ajp--0.0.0.0-8009-1) Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: No operations allowed after connection closed.Connection was implicitly closed by the driver.

11:20:59,571 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

11:20:59,571 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)

11:20:59,572 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

11:20:59,572 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at java.lang.reflect.Constructor.newInstance(Constructor.java:526)

11:20:59,572 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)

11:20:59,572 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at com.mysql.jdbc.Util.getInstance(Util.java:381)

11:20:59,573 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:984)

11:20:59,573 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:956)

11:20:59,573 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:926)

11:20:59,573 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at com.mysql.jdbc.ConnectionImpl.throwConnectionClosedException(ConnectionImpl.java:1160)

11:20:59,573 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at com.mysql.jdbc.ConnectionImpl.checkClosed(ConnectionImpl.java:1147)

11:20:59,574 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at com.mysql.jdbc.ConnectionImpl.prepareStatement(ConnectionImpl.java:4224)

11:20:59,574 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at com.mysql.jdbc.ConnectionImpl.prepareStatement(ConnectionImpl.java:4190)

11:20:59,574 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$5.doPrepare(StatementPreparerImpl.java:161)

11:20:59,574 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at org.hibernate.engine.jdbc.internal.StatementPreparerImpl$StatementPreparationTemplate.prepareStatement(StatementPreparerImpl.java:182)

11:20:59,575 ERROR [stderr] (ajp--0.0.0.0-8009-1)   ... 55 more

11:20:59,575 ERROR [stderr] (ajp--0.0.0.0-8009-1) Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: Communications link failure
11:20:59,575 ERROR [stderr] (ajp--0.0.0.0-8009-1) 
11:20:59,575 ERROR [stderr] (ajp--0.0.0.0-8009-1) The last packet successfully received from the server was 70,060 milliseconds ago.  The last packet sent successfully to the server was 0 milliseconds ago.

11:20:59,575 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)

11:20:59,576 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)

11:20:59,576 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)

11:20:59,576 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at java.lang.reflect.Constructor.newInstance(Constructor.java:526)

11:20:59,576 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at com.mysql.jdbc.Util.handleNewInstance(Util.java:406)

11:20:59,576 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1074)

11:20:59,577 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:3052)

11:20:59,577 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2938)

11:20:59,577 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3481)

11:20:59,577 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1959)

11:20:59,577 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2109)

11:20:59,578 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2648)

11:20:59,578 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2077)

11:20:59,578 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2228)

11:20:59,578 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at org.hibernate.engine.jdbc.internal.ResultSetReturnImpl.extract(ResultSetReturnImpl.java:56)

11:20:59,580 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at org.hibernate.loader.Loader.getResultSet(Loader.java:2040)

11:20:59,580 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at org.hibernate.loader.Loader.executeQueryStatement(Loader.java:1837)

11:20:59,580 ERROR [stderr] (ajp--0.0.0.0-8009-1)   ... 52 more

11:20:59,580 ERROR [stderr] (ajp--0.0.0.0-8009-1) Caused by: java.net.SocketException: Software caused connection abort: recv failed

11:20:59,581 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at java.net.SocketInputStream.socketRead0(Native Method)

11:20:59,581 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at java.net.SocketInputStream.read(SocketInputStream.java:150)

11:20:59,581 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at java.net.SocketInputStream.read(SocketInputStream.java:121)

11:20:59,589 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at com.mysql.jdbc.util.ReadAheadInputStream.fill(ReadAheadInputStream.java:113)

11:20:59,589 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at com.mysql.jdbc.util.ReadAheadInputStream.readFromUnderlyingStreamIfNecessary(ReadAheadInputStream.java:160)

11:20:59,589 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at com.mysql.jdbc.util.ReadAheadInputStream.read(ReadAheadInputStream.java:188)

11:20:59,589 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at com.mysql.jdbc.MysqlIO.readFully(MysqlIO.java:2494)

11:20:59,590 ERROR [stderr] (ajp--0.0.0.0-8009-1)   at com.mysql.jdbc.MysqlIO.reuseAndReadPacket(MysqlIO.java:2949)

11:20:59,590 ERROR [stderr] (ajp--0.0.0.0-8009-1)   ... 62 more

0 个答案:

没有答案