@Transactional弃用播放2.7

问题描述 投票:-1回答:1

由于@Transactional被弃用发挥2.7,如何升级我的代码,使实体管理事务。

java hibernate playframework
1个回答
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);
}
© www.soinside.com 2019 - 2024. All rights reserved.