由于@Transactional被弃用发挥2.7,如何升级我的代码,使实体管理事务。
据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);
}