跨CIONAL方法上的Spring重试不';t执行相同的步骤序列

跨CIONAL方法上的Spring重试不';t执行相同的步骤序列,spring,spring-retry,Spring,Spring Retry,我想在发生JPAOOptimisticLockingFailureException时重试事务服务方法 当我用@Retryable注释服务方法时 @Retryable(value = JpaOptimisticLockingFailureException.class, maxAttempts = 3, backoff = @Backoff(delay = 500, maxDelay = 1000)) Account create(AccountDtoCreate dto); 服务方法执行以下

我想在发生JPAOOptimisticLockingFailureException时重试事务服务方法

当我用@Retryable注释服务方法时

@Retryable(value = JpaOptimisticLockingFailureException.class, maxAttempts = 3, backoff = @Backoff(delay = 500, maxDelay = 1000))
Account create(AccountDtoCreate dto);
服务方法执行以下逻辑

@Transactional
public Account create(AccountDtoCreate dto) {
    Account account = mapper.map(dto, Account.class);

    Schema schema = schemaService.getByCode(dto.getSchemaCode());       
    account.getSchemas().add(schema);

    Customer customer = customerService.findOrCreate(dto.getCustomer());
    account.setCustomer(customer);

    Account savedAccount = repository.save(account);
    repository.flush();
    return savedAccount;
    }
}
我一次执行2个请求(造成JPAOOptimisticLockingFailureException发生的情况)

第一个事务已提交,第二个事务抛出JPAOOptimisticLockingFailureException并重试

重试尝试在插入客户时失败,而不是调用findOrCreate方法,甚至是getByCode方法


是否有可能使其正确地可检索?

经过调查,问题在于我使用@Transactional注释的方式。Create方法从未正确回滚。

经过调查,这是我使用@Transactional注释的方式存在的问题。Create方法从未正确回滚。

建议您共享您的修复程序,而不仅仅是为可能犯了相同错误的其他人修复。建议您共享您的修复程序,而不仅仅是为可能犯了相同错误的其他人修复。