首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在hibernate的事务中使用session.flush()

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

Stack Overflow用户
提问于 2019-04-12 11:43:54
回答 1查看 1.3K关注 0票数 1

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

代码语言:javascript
复制
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_update_outside_transaction=true之后,它可以正常工作。我不想使用hibernate.allow_update_outside_transaction=true.属性,因为它违背了原子性的概念。有没有办法在事务内运行刷新。

EN

回答 1

Stack Overflow用户

发布于 2019-04-12 15:26:32

不,不可能。

如果不设置hibernate.allow_update_outside_transaction=true,则默认情况下它将为false,并拒绝事务边界之外的任何更新操作。这甚至可以通过异常的名称来查看。

但是为什么hibernate.allow_update_outside_transaction=true属性反对原子性概念呢?相反,原子性的概念假设操作集将以原子方式执行,即要么完全成功,要么完全失败。事务就提供了这种原子性。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55644191

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档