2013-07-16 2 views
5

Im SpringBatch 2.1.7 릴리스 코어 및 Infrastructure jar를 사용하여 CSV 파일을 읽고이를 DB에 저장합니다.단계 실행 id = 1을 현재 버전이 1 인 잘못된 버전 (2)으로 업데이트하려고 시도했습니다.

스프링 쿼츠 스케쥴러를 사용하여 매분마다 실행할 수있는 코드가 통합되어 있습니다. 일괄 처리는 읽기 및 쓰기 기능이 제대로 작동하지만 "org.springframework.dao.OptimisticLockingFailureException : 단계 실행 ID = 1을 업데이트하려고합니다. 잘못된 버전 (2), 현재 버전이 1 "

Tx 충돌로 인해. 이 문제를 어떻게 해결할 수 있는지 제안 해주십시오.

+0

안녕 여기에 대한 업데이 트? – user2583922

+0

해결 했습니까? – surlac

+1

문제가 해결 될 수 있습니다. http://ashamathavan.blogspot.in/2010/12/optimisticlockingfailureexception.html –

답변

3

나는이 동일한 예외를 가지고 있었다.

org.springframework.dao.OptimisticLockingFailureException: 
Attempt to update step execution id=0 with wrong version (2), where current version is 3 

필자의 경우, 삼키는 공정 단계가 실패한 것이 원인이었습니다. Spring Batch는 프로세서가 고장 났음에도 불구하고 작가를 활성화 시켰습니다. 로그를 검토하여 프로세스 단계가 무언가를 완료하고 반환하는지 확인하십시오.

1

MattC가 지적한 것처럼 ItemProcessor이 도청 당했을 때이 오류가 발생했습니다. 나의 예외가 있었다, 그래서 내 프로세서가 활동 중에 어떤 이유로, 들어,이 jobrepository와 데이터 소스 연결을 종료했다 :

Encountered an error saving batch meta data for step step1 in job myjob. This job is now in an unknown state and should not be restarted. 
org.springframework.dao.OptimisticLockingFailureException: Attempt to update step execution id=1 with wrong version (1), where current version is 2 

을 스택 트레이스의 끝에서, 나는 발견 할 수 있었다 :

Caused by: com.microsoft.sqlserver.jdbc.SQLServerException: Connection is closed. 

문제를 확인하기 위해 먼저 위상을 분리합니다. 나는 NoOpProcessor와 NoOpItemWriter를 만들었다. 작업 표를 조정하면 잘 작동합니다. 그래서 제 문제는 독자가 아니 었습니다.

그런 다음 "전체"ItemWriter 구현으로 롤백하고 다시 제대로 작동했습니다. 그래서 제 문제는 작가가 아니 었습니다. "전체"프로세서를 활성화하면 오류가 다시 발생했습니다. 그래서 오류가 있었고 디버깅을 시작했습니다.

그래서, 불행하게도, 내 대답은 : 디버그 ...

public class NoOpProcessor implements ItemProcessor<Object, Object> { 
    @Override 
    public Object process(Object arg0) throws Exception { 
     System.out.println("Input object: " + Objects.toString(arg0));  
     return arg0; 
    } 
} 

public class NoOpItemWriter implements ItemWriter<Object> { 
    @Override 
    public void write(List<? extends Object> items) throws Exception { 
     if (items != null) { 
      System.out.println("Qtty of items to be written: " + items.size()); 
      for (Object obj : items) { 
       System.out.println(Objects.toString(obj)); 
      } 
     } else { 
      System.out.println("The items list is null. Nothing to be written."); 
     } 
    } 
}