2013-07-16 25 views
5

使用SpringBatch 2.1.7发布核心和基础结构jar来读取CSV文件并将其保存到数据库。尝试使用错误版本(2)更新步骤执行id = 1,其中当前版本为1

综合我的代码与Spring石英调度为每分钟运行批处理工作正常阅读和写作,但它的出现错误“org.springframework.dao.OptimisticLockingFailureException失败:尝试更新步执行ID = 1错误版本(2),当前版本为1“

由于发生了冲突。请建议我如何解决这个问题。

+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。调整了tasklet,它运行良好。所以我的问题不在读者身上。

然后我回滚到我的“完整”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."); 
     } 
    } 
} 
相关问题