When we are updating a record, we can use session.flush()
with Hibernate. What's the need for flush()
?
views:
59answers:
2
+1
A:
Flushing the Session gets the data that is currently in the session synchronized with what is in the database.
More on the Hibernate website:
flush()
is useful, because there are absolutely no guarantees about when the Session executes the JDBC calls, only the order in which they are executed - except you use flush()
.
The MYYN
2010-07-10 18:12:38
+1
A:
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). Hibernate will flush changes automatically for you:
- before 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,...).
Pascal Thivent
2010-07-10 18:35:43