Hibernate: A managed entity is saved without calling save()

Dirty checking flushes changes at commit. Calling save() on a managed entity is a no-op people add out of habit.

Code
@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
}
Output
Hibernate: update orders set name=? where id=?
Issued at commit, by dirty checking, whether or not save() was called.
Advertisement

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