【问题标题】:How to make a method transactional in micronaut如何在 micronaut 中使方法具有事务性
【发布时间】:2021-07-07 11:35:37
【问题描述】:

我在我的应用程序中使用带有 sqlite db 的 micronaut,服务类方法如下所示:-

   private void loadListIntoDb(Stream<EmpDto> lines) {
       try {
            empRepository.deleteAll();
            lines.forEach(empRepository::saveEmpList);
        } catch (Exception ex) {
            throw new RuntimeException("error while loading file into db", ex);
        }
    }

我想要的是如果 saveEmpList 失败,所有通过 deleteAll 方法删除的数据也应该恢复。

我试过这样测试,但它没有回滚删除的项目:

   @Transactional
   private void loadListIntoDb(Stream<EmpDto> lines) {
       try {
            empRepository.deleteAll();
            throw new Exception("test exception");
        } catch (Exception ex) {
            throw new RuntimeException("error while loading file into db", ex);
        }
    }

我有什么遗漏的吗?

问候,

【问题讨论】:

    标签: sqlite transactions micronaut


    【解决方案1】:

    终于解决了。我们不能在 Micronaut 中使私有方法具有事务性。我们需要将该方法设为公开。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-12-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-29
      相关资源
      最近更新 更多