Hibernate中session.flush()有什么用 [英] What's the use of session.flush() in Hibernate
问题描述
当我们更新记录时,我们可以将 session.flush()
与 Hibernate 一起使用.flush()
需要什么?
When we are updating a record, we can use session.flush()
with Hibernate. What's the need for flush()
?
推荐答案
刷新会话会强制 Hibernate 将 Session
的内存状态与数据库同步(即将更改写入数据库).默认情况下,Hibernate 会自动为您刷新更改:
Flushing the session forces Hibernate to synchronize the in-memory state of the Session
with the database (i.e. to write changes to the database). By default, Hibernate will flush changes automatically for you:
- 在一些查询执行之前
- 提交事务时
允许显式刷新 Session
提供了在某些情况下可能需要的更精细的控制(以获得分配的 ID,控制会话的大小,...).
Allowing to explicitly flush the Session
gives finer control that may be required in some circumstances (to get an ID assigned, to control the size of the Session,...).
这篇关于Hibernate中session.flush()有什么用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!