我正在使用批处理控制器从数据库中读取记录并将其转换为xml进行处理。我已经包含SQLException的跳过异常并显式抛出异常但在抛出SQLExceotion后无法读取下一条记录。请检查以下配置一次......
<batch:job id="batchSegmentationJob" job-repository="jobRepository" restartable="true">
<batch:listeners>
<batch:listener ref="segmentationJobExecutionListener" />
</batch:listeners>
<batch:step id="batchSegmentationStep">
<batch:tasklet transaction-manager="batchFrameworkTransactionManager">
<batch:transaction-attributes
propagation="REQUIRES_NEW" isolation="READ_COMMITTED" />
<batch:chunk
commit-interval="5"
skip-limit="30"
retry-policy="segmentationRetryPolicy">
<batch:skippable-exception-classes>
<batch:include class="java.lang.ClassCastException" /> -->
<batch:include class="java.sql.SQLException"/>
</batch:skippable-exception-classes>
<batch:reader>
<ref bean="pagingItemReader" />
</batch:reader>
<batch:processor>
<ref bean="segmentationRequestProcessor" />
</batch:processor>
<!-- <batch:writer>
<ref bean="updateAccounts" />
</batch:writer> -->
<batch:writer>
<ref bean="segmentationItemWriter" />
</batch:writer>
<batch:listeners>
<batch:listener ref="segmentationSkipListener" />
<batch:listener ref="segmentationStepListener" />
<batch:listener ref="segmentationRetryListener" />
</batch:listeners>
</batch:chunk>
</batch:tasklet>
</batch:step>
</batch:job>
我正在抛出异常如下
@Override
public String mapRow(ResultSet rs, int rowNum) throws SQLException {
final Logger logger = LoggerFactory.getLogger(SegmentationRequestRowMapper.class);
String cnsmr_accnt_id = null;
try {
cnsmr_accnt_id = String.valueOf(rs.getInt("cnsmr_accnt_id"));
if(logger.isDebugEnabled()) {
logger.debug("Started reading record for account id : "+cnsmr_accnt_id);
}
processedAccounts.add(rs.getInt("cnsmr_accnt_id"));
//acntDetailsUDPIds.add(rs.getString("ID"));
if(cnsmr_accnt_id.equals("16740")) {//4235
throw new SQLException(); //SegmentationRequestRowMapper.java:87
}
Request rq = new Request();
rq.setAccountData(populateAccountData(rs, cnsmr_accnt_id));
rq.setCustomerData(populateCustomerData(rs, cnsmr_accnt_id));
rq.setDecisions(populateBlazeDecision());
//Marshalling data fetch from database into xml string
String xmlString = marshal(rq);
if(logger.isDebugEnabled()) {
logger.debug("Marshalled Request XML String : \n"+xmlString);
}
return xmlString;
} catch (Exception e) {
logger.error("Exception occurred while reading cnsmr_accnt_id : {}" , cnsmr_accnt_id);
throw e;
}
}
异常Stacktrace:
INFO: Executing step: [batchSegmentationStep]
2015-02-20 15:38:31,766 [main] DEBUG com.fico.ybsmcr.batch.domain.rowmapper.SegmentationRequestRowMapper - Started reading record for account id : 4235
2015-02-20 15:38:31,766 [main] ERROR com.fico.ybsmcr.batch.domain.rowmapper.SegmentationRequestRowMapper - Exception occurred while reading cnsmr_accnt_id : 4235
Feb 20, 2015 3:38:31 PM org.springframework.beans.factory.xml.XmlBeanDefinitionReader loadBeanDefinitions
INFO: Loading XML bean definitions from class path resource [org/springframework/jdbc/support/sql-error-codes.xml]
Feb 20, 2015 3:38:31 PM org.springframework.jdbc.support.SQLErrorCodesFactory <init>
INFO: SQLErrorCodes loaded: [DB2, Derby, H2, HSQL, Informix, MS-SQL, MySQL, Oracle, PostgreSQL, Sybase]
2015-02-20 15:38:31,810 [main] ERROR APPLICATION - Skipping... An error has occured while reading data. Details 'org.springframework.jdbc.UncategorizedSQLException: StatementCallback; uncategorized SQLException for SQL [SELECT TOP 6400 ca.cnsmr_accnt_id,ad.UDEFHost,ad.UDEFSecAddPostCode,d.UDEFCurrLTV,d.UDEFOpeningLTV,ad.UDEFMonthsDown,d.UDEFSecChargePresent,d.UDEFPartLoanReason,d.UDEFIncSelfCertified,ai.UDEFIEXDate,(CASE WHEN cpa.UDEFCurPerEndDt IS NULL THEN cpa.UDEFCurPerStrtDt ELSE cpa.UDEFCurPerEndDt END) ArrearsStatusLastClear,ad.UDEFAccState,t.tag_shrt_nm,cmi.UDEFCMI,d.UDEFRiskNavScore,d.UDEFLettingInProgress,d.UDEFAuthorizedLet,d.UDEFUnauthorizedLet,d.UDEFCreditRepair,d.UDEFIncMult,t.tag_id,ad.ID FROM cnsmr_accnt ca INNER JOIN UDEFTestAccountDetails ad ON ca.cnsmr_accnt_id = ad.cnsmr_accnt_id AND ad.ID = (SELECT MAX(ID) from UDEFTestAccountDetails WHERE cnsmr_accnt_id=ca.cnsmr_accnt_id) INNER JOIN UDEFDecisioning d ON d.cnsmr_accnt_id = ca.cnsmr_accnt_id INNER JOIN UDEFCurPerArrs cpa ON cpa.cnsmr_accnt_id = ca.cnsmr_accnt_id INNER JOIN UDEFCMI cmi ON cmi.cnsmr_accnt_id = ca.cnsmr_accnt_id INNER JOIN cnsmr_accnt_tag cat ON cat.cnsmr_accnt_id = ca.cnsmr_accnt_id AND cat.cnsmr_accnt_sft_delete_flg ='N' INNER JOIN tag t ON t.tag_id = cat.tag_id INNER JOIN UDEFAccountIEX ai ON ai.cnsmr_accnt_id = ca.cnsmr_accnt_id WHERE t.tag_shrt_nm IN ('CLEAR','COLLECT','DEBREC','INPOSS','LIT','PENLIT') ORDER BY cnsmr_accnt_id ASC]; SQL state [null]; error code [0]; null; nested exception is java.sql.SQLException'. For more details can be found in system log
2015-02-20 15:38:31,820 [main] ERROR BATCH - Exception occured:
org.springframework.jdbc.UncategorizedSQLException: StatementCallback; uncategorized SQLException for SQL [SELECT TOP 6400 ca.cnsmr_accnt_id,ad.UDEFHost,ad.UDEFSecAddPostCode,d.UDEFCurrLTV,d.UDEFOpeningLTV,ad.UDEFMonthsDown,d.UDEFSecChargePresent,d.UDEFPartLoanReason,d.UDEFIncSelfCertified,ai.UDEFIEXDate,(CASE WHEN cpa.UDEFCurPerEndDt IS NULL THEN cpa.UDEFCurPerStrtDt ELSE cpa.UDEFCurPerEndDt END) ArrearsStatusLastClear,ad.UDEFAccState,t.tag_shrt_nm,cmi.UDEFCMI,d.UDEFRiskNavScore,d.UDEFLettingInProgress,d.UDEFAuthorizedLet,d.UDEFUnauthorizedLet,d.UDEFCreditRepair,d.UDEFIncMult,t.tag_id,ad.ID FROM cnsmr_accnt ca INNER JOIN UDEFTestAccountDetails ad ON ca.cnsmr_accnt_id = ad.cnsmr_accnt_id AND ad.ID = (SELECT MAX(ID) from UDEFTestAccountDetails WHERE cnsmr_accnt_id=ca.cnsmr_accnt_id) INNER JOIN UDEFDecisioning d ON d.cnsmr_accnt_id = ca.cnsmr_accnt_id INNER JOIN UDEFCurPerArrs cpa ON cpa.cnsmr_accnt_id = ca.cnsmr_accnt_id INNER JOIN UDEFCMI cmi ON cmi.cnsmr_accnt_id = ca.cnsmr_accnt_id INNER JOIN cnsmr_accnt_tag cat ON cat.cnsmr_accnt_id = ca.cnsmr_accnt_id AND cat.cnsmr_accnt_sft_delete_flg ='N' INNER JOIN tag t ON t.tag_id = cat.tag_id INNER JOIN UDEFAccountIEX ai ON ai.cnsmr_accnt_id = ca.cnsmr_accnt_id WHERE t.tag_shrt_nm IN ('CLEAR','COLLECT','DEBREC','INPOSS','LIT','PENLIT') ORDER BY cnsmr_accnt_id ASC]; SQL state [null]; error code [0]; null; nested exception is java.sql.SQLException
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:84) ~[spring-jdbc-4.0.4.RELEASE.jar:4.0.4.RELEASE]
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81) ~[spring-jdbc-4.0.4.RELEASE.jar:4.0.4.RELEASE]
at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81) ~[spring-jdbc-4.0.4.RELEASE.jar:4.0.4.RELEASE]
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:413) ~[spring-jdbc-4.0.4.RELEASE.jar:4.0.4.RELEASE]
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:468) ~[spring-jdbc-4.0.4.RELEASE.jar:4.0.4.RELEASE]
at org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:478) ~[spring-jdbc-4.0.4.RELEASE.jar:4.0.4.RELEASE]
at org.springframework.batch.item.database.JdbcPagingItemReader.doReadPage(JdbcPagingItemReader.java:210) ~[spring-batch-infrastructure-2.2.6.RELEASE.jar:na]
at org.springframework.batch.item.database.AbstractPagingItemReader.doRead(AbstractPagingItemReader.java:108) ~[spring-batch-infrastructure-2.2.6.RELEASE.jar:na]
at org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.read(AbstractItemCountingItemStreamItemReader.java:83) ~[spring-batch-infrastructure-2.2.6.RELEASE.jar:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.7.0_51]
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) ~[na:1.7.0_51]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[na:1.7.0_51]
at java.lang.reflect.Method.invoke(Unknown Source) ~[na:1.7.0_51]
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:317) ~[spring-aop-4.0.4.RELEASE.jar:4.0.4.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:190) ~[spring-aop-4.0.4.RELEASE.jar:4.0.4.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:157) ~[spring-aop-4.0.4.RELEASE.jar:4.0.4.RELEASE]
at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:133) ~[spring-aop-4.0.4.RELEASE.jar:4.0.4.RELEASE]
at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:121) ~[spring-aop-4.0.4.RELEASE.jar:4.0.4.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179) ~[spring-aop-4.0.4.RELEASE.jar:4.0.4.RELEASE]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:207) ~[spring-aop-4.0.4.RELEASE.jar:4.0.4.RELEASE]
at com.sun.proxy.$Proxy12.read(Unknown Source) ~[na:na]
at org.springframework.batch.core.step.item.SimpleChunkProvider.doRead(SimpleChunkProvider.java:91) ~[spring-batch-core-2.2.6.RELEASE.jar:na]
at org.springframework.batch.core.step.item.FaultTolerantChunkProvider.read(FaultTolerantChunkProvider.java:87) ~[spring-batch-core-2.2.6.RELEASE.jar:na]
at org.springframework.batch.core.step.item.SimpleChunkProvider$1.doInIteration(SimpleChunkProvider.java:114) ~[spring-batch-core-2.2.6.RELEASE.jar:na]
at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:368) [spring-batch-infrastructure-2.2.6.RELEASE.jar:na]
at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:215) [spring-batch-infrastructure-2.2.6.RELEASE.jar:na]
at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:144) [spring-batch-infrastructure-2.2.6.RELEASE.jar:na]
at org.springframework.batch.core.step.item.SimpleChunkProvider.provide(SimpleChunkProvider.java:108) ~[spring-batch-core-2.2.6.RELEASE.jar:na]
at org.springframework.batch.core.step.item.ChunkOrientedTasklet.execute(ChunkOrientedTasklet.java:69) ~[spring-batch-core-2.2.6.RELEASE.jar:na]
at org.springframework.batch.core.step.tasklet.TaskletStep$ChunkTransactionCallback.doInTransaction(TaskletStep.java:395) [spring-batch-core-2.2.6.RELEASE.jar:na]
at org.springframework.transaction.support.TransactionTemplate.execute(TransactionTemplate.java:133) [spring-tx-4.0.4.RELEASE.jar:4.0.4.RELEASE]
at org.springframework.batch.core.step.tasklet.TaskletStep$2.doInChunkContext(TaskletStep.java:267) [spring-batch-core-2.2.6.RELEASE.jar:na]
at org.springframework.batch.core.scope.context.StepContextRepeatCallback.doInIteration(StepContextRepeatCallback.java:77) [spring-batch-core-2.2.6.RELEASE.jar:na]
at org.springframework.batch.repeat.support.RepeatTemplate.getNextResult(RepeatTemplate.java:368) [spring-batch-infrastructure-2.2.6.RELEASE.jar:na]
at org.springframework.batch.repeat.support.RepeatTemplate.executeInternal(RepeatTemplate.java:215) [spring-batch-infrastructure-2.2.6.RELEASE.jar:na]
at org.springframework.batch.repeat.support.RepeatTemplate.iterate(RepeatTemplate.java:144) [spring-batch-infrastructure-2.2.6.RELEASE.jar:na]
at org.springframework.batch.core.step.tasklet.TaskletStep.doExecute(TaskletStep.java:253) [spring-batch-core-2.2.6.RELEASE.jar:na]
at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:195) [spring-batch-core-2.2.6.RELEASE.jar:na]
at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:141) [spring-batch-core-2.2.6.RELEASE.jar:na]
at org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:64) [spring-batch-core-2.2.6.RELEASE.jar:na]
at org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:60) [spring-batch-core-2.2.6.RELEASE.jar:na]
at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:151) [spring-batch-core-2.2.6.RELEASE.jar:na]
at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:130) [spring-batch-core-2.2.6.RELEASE.jar:na]
at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:135) [spring-batch-core-2.2.6.RELEASE.jar:na]
at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:301) [spring-batch-core-2.2.6.RELEASE.jar:na]
at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:134) [spring-batch-core-2.2.6.RELEASE.jar:na]
at org.springframework.core.task.SyncTaskExecutor.execute(SyncTaskExecutor.java:50) [spring-core-4.0.4.RELEASE.jar:4.0.4.RELEASE]
at org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:127) [spring-batch-core-2.2.6.RELEASE.jar:na]
at org.springframework.batch.core.launch.support.SimpleJobOperator.start(SimpleJobOperator.java:308) [spring-batch-core-2.2.6.RELEASE.jar:na]
at com.fico.ybsmcr.batch.domain.job.main.SegmentationJobMain.launch(SegmentationJobMain.java:96) [classes/:na]
at com.fico.ybsmcr.batch.domain.job.main.SegmentationJobMain.main(SegmentationJobMain.java:48) [classes/:na]
Caused by: java.sql.SQLException: null
at com.fico.ybsmcr.batch.domain.rowmapper.SegmentationRequestRowMapper.mapRow(SegmentationRequestRowMapper.java:87) ~[classes/:na]
at com.fico.ybsmcr.batch.domain.rowmapper.SegmentationRequestRowMapper.mapRow(SegmentationRequestRowMapper.java:1) ~[classes/:na]
at org.springframework.batch.item.database.JdbcPagingItemReader$PagingRowMapper.mapRow(JdbcPagingItemReader.java:348) ~[spring-batch-infrastructure-2.2.6.RELEASE.jar:na]
at org.springframework.jdbc.core.RowMapperResultSetExtractor.extractData(RowMapperResultSetExtractor.java:93) ~[spring-jdbc-4.0.4.RELEASE.jar:4.0.4.RELEASE]
at org.springframework.jdbc.core.RowMapperResultSetExtractor.extractData(RowMapperResultSetExtractor.java:60) ~[spring-jdbc-4.0.4.RELEASE.jar:4.0.4.RELEASE]
at org.springframework.jdbc.core.JdbcTemplate$1QueryStatementCallback.doInStatement(JdbcTemplate.java:457) ~[spring-jdbc-4.0.4.RELEASE.jar:4.0.4.RELEASE]
at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:402) ~[spring-jdbc-4.0.4.RELEASE.jar:4.0.4.RELEASE]
... 47 common frames omitted
2015-02-20 15:38:31,865 [main] DEBUG BATCH - afterJob() job done. execution: 30, summary: JobExecution: id=30, version=1, startTime=Fri Feb 20 15:38:31 IST 2015, endTime=Fri Feb 20 15:38:31 IST 2015, lastUpdated=Fri Feb 20 15:38:31 IST 2015, status=COMPLETED, exitStatus=exitCode=COMPLETED;exitDescription=, job=[JobInstance: id=30, version=0, Job=[batchSegmentationJob]], jobParameters=[{instance=1424426911440, cnsmr_id=1}]
请通知我提供任何其他信息......
答案 0 :(得分:0)
spring框架JDBC模板在已检查的SQLException
和未检查的DataAccessException
层次结构之间进行转换。在这种情况下:org.springframework.jdbc.UncategorizedSQLException
。
因此,您应该将步骤配置为在org.springframework.dao.DataAccessException
而不是java.sql.SQLException
上重试。
答案 1 :(得分:0)
我看到作业是COMPLETED
。
您可以打印记录读取和记录来自列表器的afterJob(JobExecution jobExecution)
方法吗?
stepExecution.getReadCount();
stepExecution.getWriteCount();
此查询返回多少条记录(从stackTrace中选择该查询)?
SELECT TOP 6400 ca.cnsmr_accnt_id,ad.UDEFHost,ad.UDEFSecAddPostCode,d.UDEFCurrLTV,d.UDEFOpeningLTV,ad.UDEFMonthsDown,d.UDEFSecChargePresent,d.UDEFPartLoanReason,d.UDEFIncSelfCertified,ai.UDEFIEXDate,(CASE WHEN cpa.UDEFCurPerEndDt IS NULL THEN cpa.UDEFCurPerStrtDt ELSE cpa.UDEFCurPerEndDt END) ArrearsStatusLastClear,ad.UDEFAccState,t.tag_shrt_nm,cmi.UDEFCMI,d.UDEFRiskNavScore,d.UDEFLettingInProgress,d.UDEFAuthorizedLet,d.UDEFUnauthorizedLet,d.UDEFCreditRepair,d.UDEFIncMult,t.tag_id,ad.ID FROM cnsmr_accnt ca INNER JOIN UDEFTestAccountDetails ad ON ca.cnsmr_accnt_id = ad.cnsmr_accnt_id AND ad.ID = (SELECT MAX(ID) from UDEFTestAccountDetails WHERE cnsmr_accnt_id=ca.cnsmr_accnt_id) INNER JOIN UDEFDecisioning d ON d.cnsmr_accnt_id = ca.cnsmr_accnt_id INNER JOIN UDEFCurPerArrs cpa ON cpa.cnsmr_accnt_id = ca.cnsmr_accnt_id INNER JOIN UDEFCMI cmi ON cmi.cnsmr_accnt_id = ca.cnsmr_accnt_id INNER JOIN cnsmr_accnt_tag cat ON cat.cnsmr_accnt_id = ca.cnsmr_accnt_id AND cat.cnsmr_accnt_sft_delete_flg ='N' INNER JOIN tag t ON t.tag_id = cat.tag_id INNER JOIN UDEFAccountIEX ai ON ai.cnsmr_accnt_id = ca.cnsmr_accnt_id WHERE t.tag_shrt_nm IN ('CLEAR','COLLECT','DEBREC','INPOSS','LIT','PENLIT') ORDER BY cnsmr_accnt_id ASC