title: Springbatch failing | Could not roll back JDBC transaction
body: <p>We have several jobs running in springbatch. We restarted the server this morning and afterwards we started having issues with two of the jobs. The BATCH_STEP_EXECUTION table shows the following exit message for each failed execution:</p>
  
  <pre><code>org.springframework.transaction.TransactionSystemException: Could not roll back JDBC transaction; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Connection.close() has already been called. Invalid operation in this state.
      at org.springframework.jdbc.datasource.DataSourceTransactionManager.doRollback(DataSourceTransactionManager.java:286)
      at org.springframework.transaction.support.AbstractPlatformTransactionManager.processRollback(AbstractPlatformTransactionManager.java:846)
      at org.springframework.transaction.support.AbstractPlatformTransactionManager.rollback(AbstractPlatformTransactionManager.java:823)
      at org.springframework.transaction.support.TransactionTemplate.rollbackOnException(TransactionTemplate.java:162)
      at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:135)
      at org.springframework.batch.core.step.tasklet.TaskletStep$2.doInChunkContext(TaskletStep.java:267)
      at org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:77)
      at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:368)
      at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:215)
      at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:144)
      at org.springframework.batch.core.step.tasklet.TaskletStep.doExecute(TaskletStep.java:253)
      at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:195)
      at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:141)
      at org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:64)
      at org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:60)
      at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:151)
      at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:130)
      at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:135)
      at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:301)
      at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:134)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
      at java.lang.Thread.run(Thread.ja
  </code></pre>
  
  <p>This appears to be in relation to the mysql connection the application is making, however I'm not sure what could have caused this as the application was functioning fine before the reboot. Has anyone stumbled across this before?</p>
  
  <p><strong>EDIT</strong>
  (caused by message that appears in the logs)</p>
  
  <pre><code>Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLNonTransientConnectionException: Connection.close() has already been called. Invalid operation in this state.
  </code></pre>
  
  <p><strong>Datasource</strong></p>
  
  <pre><code>javax.sql.DataSource
  </code></pre>
  
  <p><strong>Connection Pool</strong>
  Configured in context.xml file with the following format:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;Context docBase="webapps/appname" mapperContextRootRedirectEnabled="true" mapperDirectoryRedirectEnabled="true" path="/appname" reloadable="false" &gt;
  
  &lt;Resource name="jdbc/springbatchmeta"
              auth="Container"
              type="javax.sql.DataSource"
              username="${jobmeta.username}"
              password="${jobmeta.password}"
              driverClassName="${mysql.driverClass}"
              url="${jobmeta.url}"
              initialSize="2"
              maxTotal="20"
              maxIdle="10"
              minIdle="2"/&gt;
  
  &lt;Resource name="jdbc/firstjob"
              auth="Container"
              type="javax.sql.DataSource"
              username="${firstjob.username}"
              password="${firstjob.password}"
              driverClassName="${mysql.driverClass}"
              url="${firstjob.url}"
              initialSize="2"
              maxTotal="20"
              maxIdle="10"
              minIdle="2"/&gt;
  
  &lt;Resource name="jdbc/secondjob"
              auth="Container"
              type="javax.sql.DataSource"
              username="${secondjob.username}"
              password="${secondjob.password}"
              driverClassName="${secondjob.driverClass}"
              url="${secondjob.url}"
              initialSize="2"
              maxTotal="20"
              maxIdle="10"
              minIdle="2"/&gt;
  
  &lt;/Context&gt;
  </code></pre>