Dirty checking and flushing
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
UPDATEfor changes. - No
savecall is needed for managed entities. - Flush happens at commit, and before a query that might need pending changes (auto flush), or on
flush(). IDENTITYinserts are sent atpersisttime.- Read-only code should not trigger updates; keep setters purposeful.
Draft outline details
Demonstration
@Transactional
void rename(Long id, String name) {
Product p = repo.findById(id).orElseThrow(); // select
p.setName(name); // nothing yet
} // update at commitCheck 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.
Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.