在获取所有数据之前,Spring Batch ResultSet被其他人关闭

时间:2015-12-21 22:12:25

标签: db2 spring-batch

我正在尝试将DB2源设置为Batch元数据的持久性。我得到这个堆栈跟踪:

Caused by: org.springframework.jdbc.UncategorizedSQLException: PreparedStatementCallback; uncategorized SQLException for SQL [SELECT JOB_EXECUTION_ID, START_TIME, END_TIME, STATUS, EXIT_CODE, EXIT_MESSAGE, CREATE_TIME, LAST_UPDATED, VERSION, JOB_CONFIGURATION_LOCATION from rhall.BATCH_JOB_EXECUTION where JOB_INSTANCE_ID = ? order by JOB_EXECUTION_ID desc]; SQL state [null]; error code [-4470]; [jcc][t4][10120][10898][3.57.82] Invalid operation: result set is closed. ERRORCODE=-4470, SQLSTATE=null; nested exception is com.ibm.db2.jcc.am.SqlException: [jcc][t4][10120][10898][3.57.82] Invalid operation: result set is closed. ERRORCODE=-4470, SQLSTATE=null
   at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:84)
   at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)
   at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)
   at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:645)
   at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:680)
   at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:712)
   at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:722)
   at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:777)
   at org.springframework.batch.core.repository.dao.JdbcJobExecutionDao.findJobExecutions(JdbcJobExecutionDao.java:131)
   at org.springframework.batch.core.repository.support.SimpleJobRepository.getStepExecutionCount(SimpleJobRepository.java:253)
   at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
   at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:60)
   at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:37)
   at java.lang.reflect.Method.invoke(Method.java:611)
   at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157)
   at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:99)
   at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:281)
   at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:96)
   at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
   at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207)
   at $Proxy32.getStepExecutionCount(Unknown Source)
   at org.springframework.batch.core.job.flow.JobFlowExecutor.isStepRestart(JobFlowExecutor.java:82)
   at org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:63)
   at org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:67)
   at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:169) ... 22 more
Caused by: com.ibm.db2.jcc.am.SqlException: [jcc][t4][10120][10898][3.57.82] Invalid operation: result set is closed. ERRORCODE=-4470, SQLSTATE=null
   at com.ibm.db2.jcc.am.bd.a(bd.java:660)
   at com.ibm.db2.jcc.am.bd.a(bd.java:60)
   at com.ibm.db2.jcc.am.bd.a(bd.java:103)
   at com.ibm.db2.jcc.am.zl.Db(zl.java:4219)
   at com.ibm.db2.jcc.am.zl.q(zl.java:4180)
   at com.ibm.db2.jcc.am.zl.c(zl.java:1009)
   at com.ibm.db2.jcc.am.zl.getTimestamp(zl.java:985)
   at com.ibm.ws.rsadapter.jdbc.WSJdbcResultSet.getTimestamp(WSJdbcResultSet.java:2607)
   at org.springframework.batch.core.repository.dao.JdbcJobExecutionDao$JobExecutionRowMapper.mapRow(JdbcJobExecutionDao.java:425)
   at org.springframework.batch.core.repository.dao.JdbcJobExecutionDao$JobExecutionRowMapper.mapRow(JdbcJobExecutionDao.java:396)
   at org.springframework.jdbc.core.RowMapperResultSetExtractor.extractData(RowMapperResultSetExtractor.java:93)
   at org.springframework.jdbc.core.RowMapperResultSetExtractor.extractData(RowMapperResultSetExtractor.java:60)
   at org.springframework.jdbc.core.JdbcTemplate$1.doInPreparedStatement(JdbcTemplate.java:693)
   at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:629) 
  ... 45 more 

我跟踪代码,发现了这个方法的问题:JdbcJobExecutionDao.mapRow(ResultSet rs, int rowNum)

(我正在使用Spring-batch版本3.0.6)列表粘贴方法在这里为您的  方便,

public JobExecution mapRow(ResultSet rs, int rowNum)
 throws SQLException {          
 Long id = rs.getLong(1);           
 String jobConfigurationLocation = rs.getString(10);            
 JobExecution jobExecution;             
 if (jobParameters == null) {
    jobParameters = getJobParameters(id);           
 }
 if (jobInstance == null) {
    jobExecution = new JobExecution(id, jobParameters, jobConfigurationLocation);           
 } else {
    jobExecution = new JobExecution(jobInstance, id, jobParameters, jobConfigurationLocation);          
 }
 jobExecution.setStartTime(rs.getTimestamp(2));
 jobExecution.setEndTime(rs.getTimestamp(3));
 jobExecution.setStatus(BatchStatus.valueOf(rs.getString(4)));
 jobExecution.setExitStatus(new ExitStatus(rs.getString(5), rs.getString(6)));             
 jobExecution.setCreateTime(rs.getTimestamp(7));
 jobExecution.setLastUpdated(rs.getTimestamp(8));
 jobExecution.setVersion(rs.getInt(9));          
 return jobExecution;        
}

当我追踪它时,我注意到问题出在getJobParameters(id)方法中。此方法对JOB_EXECUTION_PARAMS表执行另一个查询,以查找给定作业ID的参数。但是在此方法中,getConnection方法返回与当前上下文中相同的连接。查询之后,finally块关闭resultSet。因此,当控件返回到mapRow方法时,它在此行失败:

jobExecution.setStartTime(rs.getTimestamp(2));  

这是因为rs方法已经关闭了getJobParameters(id)

想知道我做错了吗?请指出我。 非常感谢。

1 个答案:

答案 0 :(得分:0)

从我使用Batch Infrastructure类的方法中删除@Transactional,即JobExplorer,解决了已关闭的ResultSet周围的问题。