正如我的标题所述,我在我的应用程序中使用 hibernate Auto
刷新模式机制。因此,当我更改 hibernate 持久对象中的任何数据时,它会自动反射(reflect)在数据库中。我不想要这个。所以我找到了使用 FlushMode Commit
的解决方案。
所以这是我的实际问题:
- 使用
Commit
刷新模式而不是Auto
会更好吗?和 文档中的这句话是什么意思?
The Session is sometimes flushed before query execution in order to ensure that queries never return stale state.
http://docs.jboss.org/hibernate/orm/3.5/javadoc/org/hibernate/FlushMode.html
最佳答案
Hibernate(和 JPA)旨在自动检测对持久对象的更改并将其持久保存到数据库中。没有“保存”操作。
如果你不想保存东西,你应该使用分离的对象。要么使用 StatelessSession
加载它们,要么在加载对象后调用 detach。这会将它们从将自动保存它们的监视中删除。
不要乱用冲洗设置,以后只会让你头疼。
关于java - 使用什么刷新模式 'Auto' 或 'Commit',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18149876/