Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring batch 尝试使用错误版本(2)更新步骤执行id=1,其中当前版本为1_Spring Batch_Spring Transactions - Fatal编程技术网

Spring batch 尝试使用错误版本(2)更新步骤执行id=1,其中当前版本为1

Spring batch 尝试使用错误版本(2)更新步骤执行id=1,其中当前版本为1,spring-batch,spring-transactions,Spring Batch,Spring Transactions,Im使用Springbatch2.1.7版本核心和基础设施JAR读取CSV文件并将其保存到DB 将我的代码与Spring quartz scheduler集成,每分钟运行一次,批处理在读写方面工作正常,但由于错误“org.springframework.dao.OptimisticLockingFailureException:尝试使用错误版本(2)更新步骤执行id=1,其中当前版本为1”而失败 由于Tx冲突。请建议我如何解决此问题。我也有同样的例外 org.springframework.da

Im使用Springbatch2.1.7版本核心和基础设施JAR读取CSV文件并将其保存到DB

将我的代码与Spring quartz scheduler集成,每分钟运行一次,批处理在读写方面工作正常,但由于错误“org.springframework.dao.OptimisticLockingFailureException:尝试使用错误版本(2)更新步骤执行id=1,其中当前版本为1”而失败


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

我也有同样的例外

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

在我的案例中,这是由于流程步骤失败导致的,该步骤正在被吞咽。Spring批处理激活了writer,即使处理器出现了故障。查看您的日志,确保您的流程步骤正在完成并返回一些内容。

正如MattC所指出的,当我的
项目处理器
出现错误时,我出现了此错误。出于某种原因,在我的处理器活动期间,它关闭了与
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
在stacktrace的末尾,我能够找到:

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.");
        }
    }
}
公共类NoOpProcessor实现ItemProcessor{
@凌驾
公共对象进程(对象arg0)引发异常{
System.out.println(“输入对象:+Objects.toString(arg0));
返回arg0;
}
}
公共类NoOpItemWriter实现ItemWriter{
@凌驾
公共无效写入(列表
  • 当使用Hibernate并更新到版本>5时,也会发生这种情况。问题是序列生成默认值已更改。但如果仍使用旧序列,则会将其弄得一团糟。此问题的迹象是在实际异常发生之前出现错误和警告日志。它们类似于:
    >SQL错误:1,SQLState:23000
    ORA-00001:唯一约束(..)冲突
    。 表中有负主键(为每个项设置提交)。 要解决此问题,请在persistence.xml中将属性
    hibernate.id.new_generator_mappings
    设置为
    false

    链接:

  • 在搜索解决方案时,我无意中发现了另一个可能导致此问题的问题:使用
    MapJobRepositoryFactoryBean
    ResourcesTransansActionManager
    (假定它不会持久化数据)时,重复条目会持久化

    链接:


您好,这方面有什么更新吗?您解决了吗?这可能会解决您的问题