Card 01/ 07
All 7 cards
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.
@Transactional
void bumpFareNoExplicitSave(Long id) {
FareEntity fare = repo.findById(id).orElseThrow();
fare.amount = 99.0;
// no repo.save(fare) call anywhere
}no explicit save() called, amount is now: 99.0JPA 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.