【问题标题】:@Transactional Deprecated with Play 2.7@Transactional 已在 Play 2.7 中弃用
【发布时间】:2023-03-12 09:49:01
【问题描述】:

由于 play 2.7 不推荐使用 @Transactional,我如何升级我的代码以使实体管理器具有事务性。

【问题讨论】:

    标签: java hibernate playframework


    【解决方案1】:

    根据play documentationJPAApi.withTransaction是你需要的:

    public CompletionStage<Long> runningWithTransaction() {
        return CompletableFuture.supplyAsync(() -> {
            // lambda is an instance of Function<EntityManager, Long>
            return jpaApi.withTransaction(entityManager -> {
                Query query = entityManager.createNativeQuery("select max(age) from people");
                return (Long) query.getSingleResult();
            });
        }, executionContext);
    }
    

    【讨论】:

      猜你喜欢
      • 2016-08-18
      • 2022-11-27
      • 1970-01-01
      • 2016-11-11
      • 1970-01-01
      • 2020-06-17
      • 1970-01-01
      • 2019-06-15
      • 1970-01-01
      相关资源
      最近更新 更多