내 ItemWriter에 자동으로 존재하는 Existing DAO를 사용하여 데이터베이스에 요소를 삽입합니다.ItemWriter 롤백이지만 데이터가 데이터베이스에 커밋됩니다.
내가 다시 시작 기능을 테스트 할 수있는 5 요소에 커밋 간격 = 내 XML (읽기) 5.
, 내가 넣어 가지고 잘못된 데이터를 설정했습니다.
@Component("transactionItemWriter")
public class TransactionInteracItemWriter implements ItemStreamWriter<TransactionConciliationInterac> {
private static final Logger log = Logger.getLogger(TransactionInteracItemWriter.class);
@Autowired
private ConciliationContext conciliationContext;
@Autowired
private ServiceTransactionConciliationInterac paiementService;
private int transactionCount;
/**
* @see ItemWriter#write(java.util.List)
*/
public void write(List<? extends TransactionConciliationInterac> data) throws Exception {
int index = ++transactionCount - 1;
while (index < data.size()) {
TransactionConciliationInterac trx = data.get(index);
paiementService.insertAndReturnKey(trx,conciliationContext.getIdSommaire().toString());
index = ++transactionCount - 1;
}
}
paiementService가 DB에 데이터를 삽입 할 JdbcTemplate을을 사용하여 스프링 빈입니다 :
여기 내 ItemWriter입니다.
내 설정 : 이제
<batch:step id="traitementXmlIemtTransactionStep">
<batch:tasklet transaction-manager="transactionManager" start-limit="10">
<batch:chunk reader="IemtXmlTransactionReader" processor="IemtXmlTransactionConvertProcessor" writer="transactionItemWriter" commit-interval="5"/>
<batch:transaction-attributes isolation="DEFAULT" propagation="REQUIRED"/>
<batch:listeners>
<batch:listener ref="transactionStepListener" />
</batch:listeners>
</batch:tasklet>
</batch:step>
, 내가이 프로그램을 실행할 때, 나는 예외 (DataIntegrityEx) 얻을 참조 :
이<Rollback for RuntimeException: org.springframework.dao.DataIntegrityViolationException: PreparedStatementCallback; SQL []; Data truncation: Data too long for column 'TRANSACTIONTYPE' at row 1; nested exception is com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'TRANSACTIONTYPE' at row 1>
2012-12-11 09:50:28,949 DEBUG [org.springframework.batch.repeat.support.RepeatTemplate] - <Handling exception: org.springframework.dao.DataIntegrityViolationException, caused by: org.springframework.dao.DataIntegrityViolationException: PreparedStatementCallback; SQL []; Data truncation: Data too long for column 'TRANSACTIONTYPE' at row 1; nested exception is com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'TRANSACTIONTYPE' at row 1>
2012-12-11 09:50:28,949 DEBUG [org.springframework.batch.repeat.support.RepeatTemplate] - <Handling fatal exception explicitly (rethrowing first of 1): org.springframework.dao.DataIntegrityViolationException: PreparedStatementCallback; SQL []; Data truncation: Data too long for column 'TRANSACTIONTYPE' at row 1; nested exception is com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'TRANSACTIONTYPE' at row 1>
2012-12-11 09:50:28,950 ERROR [org.springframework.batch.core.step.AbstractStep] - <Encountered an error executing the step>
org.springframework.dao.DataIntegrityViolationException: PreparedStatementCallback; SQL []; Data truncation: Data too long for column 'TRANSACTIONTYPE' at row 1; nested exception is com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'TRANSACTIONTYPE' at row 1
at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:101)
단계의 상태는 다음과 같이 :
<Step execution complete: StepExecution: id=3, version=2, name=traitementXmlIemtTransactionStep, status=FAILED, exitStatus=FAILED, readCount=5, filterCount=0, writeCount=0 readSkipCount=0, writeSkipCount=0, processSkipCount=0, commitCount=0, rollbackCount=1>
을
이 모양은 좋아요, 나는 5 개의 요소를 읽었으며, 0은 기록되었고 1 개의 롤백이 발생했음을 알 수 있습니다.
하지만 데이터베이스를 보면 처음 4 개 요소가 커밋되었음을 알 수 있습니다 !!!!
내가 뭘 잘못하고 있는지 찾아야합니다!
감사
힘든 일이 있기 때문에 이것을 확인했지만이 서비스에는 @transactional 또는 트랜잭션 관리 XML이 없습니다. – Cygnusx1