title: How to reestablish a JDBC connection after a timeout?
body: <p>I have a long-running method which executes a large number of native SQL queries through the EntityManager (TopLink Essentials). Each query takes only milliseconds to run, but there are many thousands of them. This happens within a single EJB transaction. After 15 minutes, the database closes the connection which results in following error:</p>
  
  <pre><code>Exception [TOPLINK-4002] (Oracle TopLink Essentials - 2.1 (Build b02-p04 (04/12/2010))): oracle.toplink.essentials.exceptions.DatabaseException
  Internal Exception: java.sql.SQLException: Closed Connection
  Error Code: 17008
  Call: select ...
  Query: DataReadQuery()
  at oracle.toplink.essentials.exceptions.DatabaseException.sqlException(DatabaseException.java:319)
  .
  .
  .
  RAR5031:System Exception.
  javax.resource.ResourceException: This Managed Connection is not valid as the phyiscal connection is not usable
  at com.sun.gjc.spi.ManagedConnection.checkIfValid(ManagedConnection.java:612)
  </code></pre>
  
  <p>In the JDBC connection pool I set <code>is-connection-validation-required="true"</code> and <code>connection-validation-method="table"</code> but this did not help .</p>
  
  <p>I assumed that JDBC connection validation is there to deal with precisely this kind of errors. I also looked at TopLink extensions (http://www.oracle.com/technetwork/middleware/ias/toplink-jpa-extensions-094393.html) for some kind of timeout settings but found nothing. There is also the TopLink session configuration file (http://download.oracle.com/docs/cd/B14099_19/web.1012/b15901/sessions003.htm) but I don't think there is anything useful there either.</p>
  
  <p>I don't have access to the Oracle DBA tables, but I think that Oracle closes connections after 15 minutes according to the setting in CONNECT_TIME profile variable.</p>
  
  <p>Is there any other way to make TopLink or the JDBC pool to reestablish a closed connection?</p>
  
  <p>The database is Oracle 10g, application server is Sun Glassfish 2.1.1.</p>