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

问题描述

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

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

谢谢!

解决方案

wascommitted()不必总是返回 true 即使提交是成功即可。如果事务通过本地事务(明确地)提交,它将返回 true 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:-

这篇关于为什么transaction.wasCommitted()返回false?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 16:48