由于@Transactional在play 2.7中不建议使用,因此如何升级代码以使实体管理器成为Transactional。
答案 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);
}