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:
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,...).