You load an entity inside a `@Transactional` method, change a setter, and never call `save()`. What happens?
basicThe change is written to the database at flush/commit. A managed entity is tracked by the persistence context, and at flush Hibernate compares its current state with the snapshot taken at load time (dirty checking) and issues an UPDATE.
save()on a managed entity is effectively a no-op for updates.- Without a surrounding transaction (and with open-in-view only), the entity is still managed for the request, but nothing flushes it, so the change is silently lost.
- Does Hibernate update only the changed column? No, by default it updates all columns;
@DynamicUpdaterestricts the SET clause to changed ones. - What if the method is
@Transactional(readOnly = true)? Spring sets flush mode to MANUAL for the session (Hibernate), so no flush happens and the change is not persisted.