Dirty Checking, Write-Behind and Flush Modes
Learn Dirty Checking, Write-Behind and Flush Modes (Phase 8 · Transactions and Concurrency (Core), Hibernate) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.
Dirty checking • When an entity is loaded, Hibernate keeps a snapshot of its state ("loaded state"). At flush time it compares every managed entity's current state with its snapshot; each difference becomes an UPDATE automatically: no save() call is needed. • Cost: proportional to the number of managed entities × properties. Reduce with read-only entities/queries, DTO projections, clear() in batches and bytecode enhancement (dirty tracking by instrumentation: hibernate.enhancer.enableDirtyTracking ). • By default UPDATE statements include all columns (statement reuse); @DynamicUpdate includes...