title: JDBI (not JDBC) Connection Closed - how to handle
body: <p>(<strong>This is a JDBI question</strong>, Jarrod Roberson, not just a Postgres question.)</p>
  
  <p>I have a business class calling a DAO method multiple times. After around 15 minutes, that dies with a Connection closed error from Postgres.</p>
  
  <pre><code>! 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
  </code></pre>
  
  <p>This is the way the Dao class is instantiated:</p>
  
  <pre><code>final DBI jdbi = factory.build(environment, configuration.getHuiDbDatabase(), "postgres");
  
      final MyDao myDao = jdbi.onDemand(MyDao.class);
  </code></pre>
  
  <p>A and then this dao has a method annotated with @Transaction, which is called multiple times from the business class.</p>
  
  <p>At some point the connection is closed. What should I do to handle that, so that I can keep calling the @Transaction method?</p>