Card 01/ 07

ConceptDifficulty: Intermediate1 min

The Object Nobody Told to Save

Load a JPA entity inside a @Transactional method, change one field, and call nothing else. The change reaches the database anyway.

java
@Transactional
void bumpFareNoExplicitSave(Long id) {
    FareEntity fare = repo.findById(id).orElseThrow();
    fare.amount = 99.0;
    // no repo.save(fare) call anywhere
}
text
no explicit save() called, amount is now: 99.0
run in a container — reloaded from the database after the method returns

JPA keeps a persistence context — a record of every entity it has loaded inside the current transaction — and checks each one for changes when the transaction commits. This is dirty checking: JPA doesn't need to be told what changed, because it's been watching the whole time.

Spring Data JDBC has neither. It doesn't track loaded objects, and it doesn't watch them for changes. Nothing persists until you call save() yourself — which is a different trade, not a missing feature: no watching means no surprise writes, and no dirty-checking overhead on every field of every loaded object.