为什么transaction.wasCommitted()返回false? [英] Why does transaction.wasCommitted() return false?
问题描述
我通常对hibernate和java-ee是新手,我想知道是否有人可以告诉我为什么这段代码返回false,即使从查看数据库我可以看到事务实际上已经提交:
session.beginTransaction();
session.saveOrUpdate(user);
session.getTransaction()。commit();
return session.getTransaction()。wasCommitted(); //总是假
谢谢!
true
即使提交是<强>成功即可。如果事务通过本地事务(明确地)提交
,它将返回 true
false
否则。
从 docs : -
wasCommitted
$ b 即使在成功调用
commit()后,此方法也可能返回false。作为一个例子,如果没有启动事务,基于JTA的策略no-op对commit()调用
;在这种情况下,他们还将
wascommitted()报告为false。
I am new to hibernate and java-ee in general and I was wondering if anyone could tell me why this piece of code returns false even though from looking at the database I can see the transaction was actually committed:
session.beginTransaction();
session.saveOrUpdate(user);
session.getTransaction().commit();
return session.getTransaction().wasCommitted(); //Always false
Thanks!
wasCommitted()
need not always return true
even if the commit was successful. It'll return true
if the transaction was (unequivocally) committed
via this local transaction; false
otherwise.
From the 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.
这篇关于为什么transaction.wasCommitted()返回false?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!