2012-05-18 92 views
0

当Web服务被访问时,我会随机得到这个错误。它很难复制,并且一旦我刷新它,所有功能都按预期工作。jdbc开始失败

 

    Caused by: org.hibernate.exception.JDBCConnectionException: could not execute query 
     at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:97) 
     at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66) 
     at org.hibernate.loader.Loader.doList(Loader.java:2235) 
     at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2129) 
     at org.hibernate.loader.Loader.list(Loader.java:2124) 
     at org.hibernate.loader.criteria.CriteriaLoader.list(CriteriaLoader.java:118) 
     at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1597) 
     at org.hibernate.impl.CriteriaImpl.list(CriteriaImpl.java:306) 
     at edu.asd.myproj.hibernate.adapter.CriteriaAdapter.list(CriteriaAdapter.java:380) 
     at edu.asd.myproj.DaoHibernateImpl.findByCriteria(DaoHibernateImpl.java:778) 
     at edu.asd.myproj.DaoHibernateImpl.findByCriteria(DaoHibernateImpl.java:765) 
     at edu.asd.myproj.DaoHibernateImpl.findByProperty(DaoHibernateImpl.java:361) 
     at edu.asd.myproj.ProfilesDaoImpl.count(ProfilesDaoImpl.java:81) 
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
     at java.lang.reflect.Method.invoke(Method.java:597) 
     at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:307) 
     at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:182) 
     at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:149) 
     at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:106) 
     at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171) 
     at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:204) 
     at $Proxy27.count(Unknown Source) 
     at edu.asd.myproj.ResourceProfileLoaderNew.loadProfiles(ResourceProfileLoaderNew.java:66) 
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) 
     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) 
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) 
     at java.lang.reflect.Method.invoke(Method.java:597) 
     at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleElement.invoke(InitDestroyAnnotationBeanPostProcessor.java:297) 
     at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor$LifecycleMetadata.invokeInitMethods(InitDestroyAnnotationBeanPostProcessor.java:250) 
     at org.springframework.beans.factory.annotation.InitDestroyAnnotationBeanPostProcessor.postProcessBeforeInitialization(InitDestroyAnnotationBeanPostProcessor.java:144) 
     ... 50 more 
    Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was44323 seconds ago.The last packet sent successfully to the server was 44323 seconds ago, which is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem. 
     at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) 
     at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) 
     at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) 
     at java.lang.reflect.Constructor.newInstance(Constructor.java:513) 
     at com.mysql.jdbc.Util.handleNewInstance(Util.java:406) 
     at com.mysql.jdbc.SQLError.createCommunicationsException(SQLError.java:1074) 
     at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3246) 
     at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1917) 
     at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2060) 
     at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2542) 
     at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:1734) 
     at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:1885) 
     at org.apache.commons.dbcp.DelegatingPreparedStatement.executeQuery(DelegatingPreparedStatement.java:93) 
     at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:208) 
     at org.hibernate.loader.Loader.getResultSet(Loader.java:1812) 
     at org.hibernate.loader.Loader.doQuery(Loader.java:697) 
     at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:259) 
     at org.hibernate.loader.Loader.doList(Loader.java:2232) 
     ... 79 more 
    Caused by: java.net.SocketException: Broken pipe 
     at java.net.SocketOutputStream.socketWrite0(Native Method) 
     at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92) 
     at java.net.SocketOutputStream.write(SocketOutputStream.java:136) 
     at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:65) 
     at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:123) 
     at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:3227) 
     ... 90 more 

这是我的hibernate.properties文件

# Turn on for SQL debugging 
hibernate.show_sql=true 

# Generate schema? 
hibernate.hbm2ddl.auto=validate 

#============================================================ 
# C3P0 connection pool configuration 
#============================================================ 
#changed to default values 
c3p0.acquireIncrement=hibernate.c3p0.acquire_increment 
c3p0.idleConnectionTestPeriod=hibernate.c3p0.idle_test_period 
c3p0.initialPoolSize=10 
c3p0.maxIdleTime=hibernate.c3p0.timeout 
c3p0.maxPoolSize=hibernate.c3p0.max_size 
c3p0.maxStatements=hibernate.c3p0.max_statements 
c3p0.minPoolSize=hibernate.c3p0.min_size 
c3p0.testConnectionsOnCheckout=hibernate.c3p0.validate 

被视为错误随机一次,它需要很长的时间它reappears.It消失一次刷新之前。

回答

4

请发送完整的异常堆栈跟踪,以便更多地了解读者。

这种异常通常发生在DB Connection陈旧时。

陈旧意味着:连接被服务器终止,但仍被池认为是活着的。您需要在连接中配置连接测试。对于C3P0这种方法,你必须使用以下配置:

c3p0.testConnectionOnCheckin = true 
testConnectionOnCheckout= true 

和检查更多增加结帐超时如下:

c3p0.checkoutTimeout = 0 

并测试C3P0另一个测试选项,如:

  • connectionTesterClassName
  • idleConnectionTestPeriod
  • automaticTestTable
  • preferredTestQuery

用于测试的另一种方法是通过一个JDBC pure

+0

即使添加c3p0.testConnectionOnCheckin =真后写示例代码和连接到数据库。(由DriverManagerConnection和等)我得到了同样的错误。我还向数据库URL添加了autoReconnect?= true,但仍然是相同的错误。 – icedek

+1

对不起延迟回复您的评论并感谢追加异常堆栈跟踪。当'java.net.SocketException:Broken pipe'异常发生时,其原因可能是'Database'方面,请更改数据库提供者,例如使用'MySql'或'Derby'或其他方法进行测试。 – MJM