SteelReed

Search

Search posts, questions…

JPA & HibernateQuestion 7 / 24

Middle

What is dirty checking? How is flush different from commit?

Short answer

Dirty checking: Hibernate snapshots an entity at load, compares at flush and generates the UPDATE itself. Flush sends SQL but stays inside the transaction; commit makes it final.

load: snapshot the entitysetter changes a fieldflush: comparesend UPDATEcommit: finalother tx can see

3 points to say:

  1. A managed entity you change is updated automatically.
  2. Flush is not commit: after a flush you can still roll back.
  3. Read-only work uses readOnly to stay light.

Keep reading the deep dive

Create a free account to read the full explanation and follow-up questions, mark questions as studied and review them on a schedule.