如何在hibernate中的事务中使用session.flush()

如何在hibernate中的事务中使用session.flush(),hibernate,jpa,transactions,Hibernate,Jpa,Transactions,我正在将hibernate从3.X迁移到hibernate版本5.4.2。我在执行刷新操作时遇到以下错误 javax.persistence.TransactionRequiredException: no transaction is in progress at org.hibernate.internal.AbstractSharedSessionContract.checkTransactionNeededForUpdateOperation(AbstractSharedSess

我正在将hibernate从3.X迁移到hibernate版本5.4.2。我在执行刷新操作时遇到以下错误

javax.persistence.TransactionRequiredException: no transaction is in progress
    at org.hibernate.internal.AbstractSharedSessionContract.checkTransactionNeededForUpdateOperation(AbstractSharedSessionContract.java:398)
    at org.hibernate.internal.SessionImpl.checkTransactionNeededForUpdateOperation(SessionImpl.java:3619)
    at org.hibernate.internal.SessionImpl.doFlush(SessionImpl.java:1474)
    at org.hibernate.internal.SessionImpl.flush(SessionImpl.java:1470)
设置值
hibernate.allow\u update\u outside\u transaction=true后,它工作正常。
我不想使用
hibernate.allow\u update\u outside\u transaction=true。
属性,因为它违反原子性概念。有没有办法在事务中运行刷新。

没有,没有办法

如果未设置
hibernate.allow\u update\u outside\u transaction=true
,默认情况下它将为
false
,并拒绝事务边界之外的任何更新操作。这甚至可以通过异常的名称看到

但是为什么
hibernate.allow\u update\u outside\u transaction=true
属性违反原子性概念?相反,原子性概念假设操作集将以原子方式执行,即完全成功或完全失败。事务只提供了原子性。

不,不可能

如果未设置
hibernate.allow\u update\u outside\u transaction=true
,默认情况下它将为
false
,并拒绝事务边界之外的任何更新操作。这甚至可以通过异常的名称看到


但是为什么
hibernate.allow\u update\u outside\u transaction=true
属性违反原子性概念?相反,原子性概念假设操作集将以原子方式执行,即完全成功或完全失败。事务仅提供此原子性。

请向我们显示您的代码。异常表示没有正在进行的事务,所以您需要启动事务。很难共享我当前的应用程序代码。让我尝试使用测试应用程序模拟这个问题,并与大家分享。这可能也能帮助我得到答案。请给我们看一下你的代码。异常表示没有正在进行的事务,所以您需要启动事务。很难共享我当前的应用程序代码。让我尝试使用测试应用程序模拟这个问题,并与大家分享。这可能也会帮助我得到答案。如果事务如你所说提供原子性,那么允许在事务外部进行更新会破坏原子性,从而违反原子性概念。如果事务如你所说提供原子性,那么允许在事务外部进行更新会破坏原子性,从而违反原子性概念。