什么使用冲洗模式'自动'或'提交' [英] What to use Flush Mode 'Auto' or 'Commit'
问题描述
正如我的标题所描述的,我在我的应用程序中使用了hibernate Auto
刷新模式机制。所以,当我更改hibernate持久对象中的任何数据时,它会自动反映到数据库中。我不想要这个。所以我找到了一个使用FlushMode Commit
的解决方案。
- 使用
Commit
冲洗模式代替Auto
?和 -
文档中此语句的含义是什么?
$ b
在查询执行前,Session有时会以
b $ b
的顺序刷新,以确保查询不会返回陈旧状态。
http://docs.jboss.org/hibernate/orm/3.5/javadoc/org/hibernate/FlushMode.html
Hibernate(和JPA)用于自动检测并持久化对数据库的持久对象的更改。没有保存操作。
如果您不想保存事物,则应使用分离的对象。使用 StatelessSession
加载它们,或者在加载对象后调用detach。这将它们从监控中删除,并自动保存。
不要惹恼冲洗设置,它会让您稍后头痛。
As my title described, I am using hibernate Auto
flush mode mechanism in my application. So, when I change any data in a hibernate persistent object, it reflects automatically in the database. I don't want this. So I found a solution to use FlushMode Commit
instead.
So here is my actual question:
- Is it better to use
Commit
flush mode instead ofAuto
? and What is the meaning of this statement from the documentation?
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 (and JPA) are designed to automatically detect and persist changes to persistent objects to the database. There is no "save" operation.
If you don't want things saved, you should use detached objects. Either use a StatelessSession
to load them, or call detach after loading your objects. This removes them from the monitoring that will automatically save them.
Don't mess with the flush settings, it will just give you headaches later.
这篇关于什么使用冲洗模式'自动'或'提交'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!