Dirty checking flushes changes at commit. Calling save() on a managed entity is a no-op people add out of habit.
@Transactional
public void rename(Long id, String name) {
Order o = repo.findById(id).orElseThrow();
o.setName(name); // that is all
// repo.save(o); // unnecessary - it is already managed
}
Hibernate: update orders set name=? where id=?
Issued at commit, by dirty checking, whether or not save() was called.
Run this yourself in the Online Java Compiler, spin up a live REST API in the API Sandbox, or practise with Java interview questions.
Published 2026-08-11