The process of automatically updating the database (DML queries: insert/update/delete) with the changes to the persistent object when the session is flushed (@ commit) is known as automatic dirty checking.
An object enters the persistent state when any one of the following happens:
session.save
, session.persist
, session.saveOrUpdate
, or session.merge
session.load
or session.get
Any changes to a persistent object are automatically saved to the database when the session is flushed.
Even though there is a session.flush()
method available, you generally don't need to invoke it explicitly.
A session gets flushed when the transaction is committed.