【发布时间】:2018-05-03 06:16:23
【问题描述】:
我正在使用带有 javaJPA 的 Play Framework 2.5.1,似乎嵌套事务没有按说明工作。
public TransactionEntity saveTransaction(TrasactionForm form) {
return japApi.withTransaction(() -> { //outer transaction
TransactionEntity t = jpaApi.withTransaction(() -> { //inner transaction
TransactionEntity entity = form.toEntity();
return txnDao.saveTransaction(entity);
});
return txnDao.getTransaction(entity.id); //should get the transaction from db, but throws exception saying no entity found
});
}
实际情况比上面提到的例子稍微复杂一点。我有一个外部事务并在嵌套事务中保存一个实体,并尝试在外部事务中获取刚刚保存的事务 - 而不是获取它,休眠抛出实体未找到异常。外部事务无法看到内部事务对数据库的写入。
如果我调试 Play JPA 和休眠代码,一切正常 - 是因为延迟吗?我认为这不应该发生,因为这是基本的交易原则。
我阅读并查看了 Play 现在支持嵌套事务的代码,但在我的简单案例中,它不起作用。
感谢任何帮助和提示。
【问题讨论】:
标签: hibernate jpa playframework transactions playframework-2.0