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

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

问题描述

当我们更新记录时,我们可以在Hibernate中使用 session.flush()。什么是需要 flush()

解决方案

Hibernate将 Session 的内存中状态与数据库同步(即将更改写入数据库)。默认情况下,Hibernate会自动为您刷新更改:




  • 在执行某些查询之前

  • 事务被提交



允许显式刷新 Session 在某些情况下是必需的(要分配ID,控制Session的大小,...)。

When we are updating a record, we can use session.flush() with Hibernate. What's the need for flush()?

解决方案

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:

  • before some query executions
  • when a transaction is committed

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天全站免登陆