Skip to content
Ameen Abozaid
Planned lessonJNR-028-L05

Dirty checking and flushing

  • Lesson 5 of 8
  • Junior
On This Lesson 4 topics

This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.

In this lesson

predict when SQL is sent.

Planned topics

  • Dirty checking: at flush, Hibernate compares each managed entity with its loaded snapshot and issues UPDATE for changes.
  • No save call is needed for managed entities.
  • Flush happens at commit, and before a query that might need pending changes (auto flush), or on flush().
  • IDENTITY inserts are sent at persist time.
  • Read-only code should not trigger updates; keep setters purposeful.
Draft outline details

Demonstration

java
@Transactional
void rename(Long id, String name) {
    Product p = repo.findById(id).orElseThrow(); // select
    p.setName(name);                             // nothing yet
}                                                // update at commit

Check your understanding

When does the update above run?

Show answer

At flush, which happens on commit.

Practice

Apply this lesson with the module's lab, exercises and quiz.

Lab and exercises Quiz

Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.

Continue to next lesson

Type to search levels, phases, modules and lessons.