Card 03/ 07

ComparisonDifficulty: Advanced1 min

Choosing Between Them

Neither is the safe default. Each one fits a different shape of application, on the same two axes the previous two cards just demonstrated.

Spring Data JDBC vs Spring Data JPA
Compared onSpring Data JDBCSpring Data JPA
Persistence contextNoneYes, with dirty checking
Lazy loadingNone — loads in fullYes, and it can fail outside a transaction
SQL behaviourPredictable, close to what you wroteCan be surprising — generated, sometimes deferred
FitsSimple, mostly-flat domains; microservices; predictable CRUDComplex relationships, rich domain models, an existing Hibernate investment

A microservice with a flat domain and predictable SQL requirements is Spring Data JDBC's case — there's nothing complex enough for a persistence context to be worth its cost. A domain with genuine relationship depth, where a reader benefits from letting the framework manage loading and change-tracking rather than doing both by hand, is JPA's case. Neither one is "the safer default": each is safer for the domain it fits.