总的来说,我对 hibernate 和 java-ee 很陌生,我想知道是否有人可以告诉我为什么这段代码返回 false,即使通过查看数据库我可以看到事务实际上已提交:
session.beginTransaction();
session.saveOrUpdate(user);
session.getTransaction().commit();
return session.getTransaction().wasCommitted(); //Always false
谢谢!
最佳答案
即使提交成功,
wasCommissed()
也不必总是返回true
。如果事务(明确地)通过此本地事务提交
,它将返回true
;否则假
。
来自docs :-
wasCommitted
This method could return false even after successful invocation of commit(). As an example, JTA based strategies no-op on commit() calls if they did not start the transaction; in that case, they also report wasCommitted() as false.
关于java - 为什么 transaction.wasCommited() 返回 false?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15503976/