我正在将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_update_outside_transaction=true之后,它可以正常工作。我不想使用hibernate.allow_update_outside_transaction=true.属性,因为它违背了原子性的概念。有没有办法在事务内运行刷新。
发布于 2019-04-12 15:26:32
不,不可能。
如果不设置hibernate.allow_update_outside_transaction=true,则默认情况下它将为false,并拒绝事务边界之外的任何更新操作。这甚至可以通过异常的名称来查看。
但是为什么hibernate.allow_update_outside_transaction=true属性反对原子性概念呢?相反,原子性的概念假设操作集将以原子方式执行,即要么完全成功,要么完全失败。事务就提供了这种原子性。
https://stackoverflow.com/questions/55644191
复制相似问题