【问题标题】:Attempt to update step execution id=1 with wrong version (2), where current version is 1尝试使用错误版本 (2) 更新步骤执行 id=1,其中当前版本为 1
【发布时间】:2013-07-14 21:20:09
【问题描述】:

我正在使用 SpringBatch 2.1.7 发布核心和基础结构 jar 来读取 CSV 文件并将其保存到 DB。

将我的代码与 Spring 石英调度程序集成以每分钟运行一次,批处理在读写方面工作正常,但失败并出现错误“org.springframework.dao.OptimisticLockingFailureException: Attempt to update step execution id=1 with wrong版本 (2),当前版本为 1"

由于 Tx 冲突。请建议我如何解决此问题。

【问题讨论】:

标签: spring-batch spring-transactions


【解决方案1】:

我也有同样的例外。

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

在我的情况下,它是由被吞下的过程步骤失败引起的。 Spring Batch 激活了 writer,即使处理器发生故障。查看您的日志以确保您的流程步骤正在完成并返回一些内容。

【讨论】:

    【解决方案2】:

    正如 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.");
            }
        }
    }
    

    【讨论】:

      【解决方案3】:

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-09-04
        • 2019-06-25
        • 1970-01-01
        • 2022-01-03
        • 1970-01-01
        • 2021-12-18
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多