Home » hibernate » DIFFERENCE BETWEEN HIBERNATE FLUSH AND COMMIT

DIFFERENCE BETWEEN HIBERNATE FLUSH AND COMMIT

Flushing the Session simply makes the data that is currently in the session synchronized with what is in the database.
However, just because you have flushed, doesn’t mean the data can’t be rolled back.
Commit does flush the session, but it also ends the unit of work.
To summarize commit does two things,
1. Commit internally does flush
2. Ends the unit of work (makes the changes permanent).
FLUSH:
Flushing the Session simply gets the data that is currently in the session synchronized with what is in the database. However, just because you have flushed, doesn’t mean the data can’t be rolled back.
Hibernate will flush changes automatically for you:
before query executions
when a transaction is committed
Flushing is the process of synchronizing the underlying persistent store with persistable state held in memory.
COMMIT:
Commit does flush the session, but it also ends the unit of work

Leave a comment