为什么transaction.wasCommitted()返回false? [英] Why does transaction.wasCommitted() return false?

查看:300
本文介绍了为什么transaction.wasCommitted()返回false?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通常对hibernate和java-ee是新手,我想知道是否有人可以告诉我为什么这段代码返回false,即使从查看数据库我可以看到事务实际上已经提交:

  session.beginTransaction(); 
session.saveOrUpdate(user);
session.getTransaction()。commit();
return session.getTransaction()。wasCommitted(); //总是假

谢谢!

解决方案

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆