intermediateThe Persistence Context — First-Level Cache, Dirty Checking & Flush
What's the difference between a flush and a commit?
A flush executes the pending SQL (INSERTs/UPDATEs/DELETEs) needed to sync the persistence context's state to the database, but doesn't make those changes permanently visible to other transactions — a flushed-but-uncommitted change is still fully rollback-able. A commit is what actually finalizes the transaction, making its effects (already flushed) permanently visible to others.
Ready to master this question?
Generate a complete walkthrough — background, the full answer in plain language, a working code example explained line by line, a real-world scenario, common mistakes, and how this same question gets asked in different ways.
Sign in to generate a response