1

这是一个 JDBI 问题,Jarrod Roberson,而不仅仅是 Postgres 问题。)

我有一个业务类多次调用 DAO 方法。大约 15 分钟后,由于 Postgres 的连接关闭错误而终止。

! Caused by: org.postgresql.util.PSQLException: This connection has been closed.
! at org.postgresql.jdbc2.AbstractJdbc2Connection.checkClosed(AbstractJdbc2Connection.java:853) ~[hui-populator.jar:0.0.180]
! at org.postgresql.jdbc2.AbstractJdbc2Connection.rollback(AbstractJdbc2Connection.java:870) ~[hui-populator.jar:0.0.180]
! at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_51]
! at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_51]
! at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_51]
! at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_51]
! at org.apache.tomcat.jdbc.pool.ProxyConnection.invoke(ProxyConnection.java:126) ~[hui-populator.jar:0.0.180]
! at org.apache.tomcat.jdbc.pool.JdbcInterceptor.invoke(JdbcInterceptor.java:109) ~[hui-populator.jar:0.0.180]
! at org.apache.tomcat.jdbc.pool.DisposableConnectionFacade.invoke(DisposableConnectionFacade.java:80) ~[hui-populator.jar:0.0.180]
! at com.sun.proxy.$Proxy39.rollback(Unknown Source) ~[na:na]
! at org.skife.jdbi.v2.tweak.transactions.LocalTransactionHandler.rollback(LocalTransactionHandler.java:90) ~[hui-populator.jar:0.0.180]
! ... 62 common frames omitted

这是 Dao 类的实例化方式:

final DBI jdbi = factory.build(environment, configuration.getHuiDbDatabase(), "postgres");

    final MyDao myDao = jdbi.onDemand(MyDao.class);

A 然后这个dao有一个用@Transaction注解的方法,从业务类中被多次调用。

在某些时候,连接关闭。我应该怎么做才能继续调用@Transaction 方法?

4

0 回答 0