Hibernate + c3p0 + postgres = SQLState:08006发送到后端时发生I / O错误

时间:2014-06-03 14:12:26

标签: hibernate timeout

嗨,我有一个Transactional带注释的服务功能,可以调用外部休息Api,有时快速,有时需要大约10秒。

当api快速返回时,一切正常,当需要太长时间时,hibernate会给我这个例外:

http-bio-8080-exec-5 03/06/2014 16:05:59,346 | WARN | org.hibernate.engine.jdbc.spi.SqlExceptionHelper | logExceptions | SQL Error: 0, SQLState: 08006
http-bio-8080-exec-5 03/06/2014 16:05:59,351 | ERROR | org.hibernate.engine.jdbc.spi.SqlExceptionHelper | logExceptions | An I/O error occured while sending to the backend.
http-bio-8080-exec-5 03/06/2014 16:05:59,353 | WARN | com.mchange.v2.c3p0.impl.NewPooledConnection | handleThrowable | [c3p0] A PooledConnection that has already signalled a Connection error is still in use!
http-bio-8080-exec-5 03/06/2014 16:05:59,354 | WARN | com.mchange.v2.c3p0.impl.NewPooledConnection | handleThrowable | [c3p0] Another error has occurred [ org.postgresql.util.PSQLException: This connection has been closed. ] which will not be reported to listeners!
org.postgresql.util.PSQLException: This connection has been closed.
    at org.postgresql.jdbc2.AbstractJdbc2Connection.checkClosed(AbstractJdbc2Connection.java:714)
    at org.postgresql.jdbc2.AbstractJdbc2Connection.rollback(AbstractJdbc2Connection.java:731)
    at com.mchange.v2.c3p0.impl.NewProxyConnection.rollback(NewProxyConnection.java:860)
    at org.hibernate.engine.transaction.internal.jdbc.JdbcTransaction.doRollback(JdbcTransaction.java:163)
    at org.hibernate.engine.transaction.spi.AbstractTransactionImpl.rollback(AbstractTransactionImpl.java:209)
    at org.springframework.orm.hibernate4.HibernateTransactionManager.doRollback(HibernateTransactionManager.java:574)
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.processRollback(AbstractPlatformTransactionManager.java:846)
    at org.springframework.transaction.support.AbstractPlatformTransactionManager.rollback(AbstractPlatformTransactionManager.java:823)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.completeTransactionAfterThrowing(TransactionAspectSupport.java:493)
    at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:264)
    at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:94)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:172)
    at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:631)

postgres服务器记录此

2014-06-03 16:04:40 CEST LOG:  unvollständige Message vom Client

unvollständige消息vom客户端~~来自客户端的不完整消息

所以我假设有任何超时......但我不知道在哪里,我的hibernate配置:

<bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
    <!-- Connection properties -->
    <property name="driverClass" value="org.postgresql.Driver" />
    <property name="jdbcUrl" value="jdbc:postgresql://localhost:5432/dbname" />
    <property name="user" value="postgres" />
    <property name="password" value="xxx" />
    <!-- Pool properties -->
    <property name="numHelperThreads" value="10" />
    <property name="acquireIncrement" value="3" />
    <property name="initialPoolSize" value="5" />
    <property name="minPoolSize" value="5" />
    <property name="maxPoolSize" value="20" />
    <property name="maxStatements" value="50" />
    <property name="idleConnectionTestPeriod" value="300000" />
    <property name="loginTimeout" value="300" />
</bean>

<property name="hibernateProperties">
        <value>
            hibernate.hbm2ddl.auto=update
            hibernate.dialect=org.hibernate.dialect.PostgreSQLDialect
            hibernate.bytecode.use_reflection_optimizer=false
            hibernate.max_fetch_depth=0
        </value>
    </property>

1 个答案:

答案 0 :(得分:3)

问题在于这一行

Restrictions.in("id", hugeidlist)

hugeidlist来自外部api并包含超过100,000个条目,这会产生一个太长的查询,我现在已经将列表拆分