@Transactional在Play 2.7中已弃用

时间:2019-02-04 03:07:34

标签: java hibernate playframework

由于@Transactional在play 2.7中不建议使用,因此如何升级代码以使实体管理器成为Transactional。

1 个答案:

答案 0 :(得分:0)

您需要play documentation JPAApi.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);
}