Hibernate中session.flush()有什么用 [英] What's the use of session.flush() in Hibernate

查看:13
本文介绍了Hibernate中session.flush()有什么用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我们更新记录时,我们可以将 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆