How to Decouple Java Persistence from Spring With a Zero-Dependency DAO Contract
A software architecture guide argues that the common practice of extending JpaRepository directly couples Java applications to Spring Data and Hibernate, undermining clean architecture. The article, part of an Evolutionary Architecture series, proposes building a dedicated DAO API module that defines persistence contracts in pure Java without any framework dependencies. It recommends splitting the typical unified save() method into separate create() and update() calls to avoid hidden SELECT queries that frameworks trigger to determine whether to INSERT or UPDATE. The guide also advocates returning null instead of Optional from database lookups, citing heap allocation overhead in high-throughput systems. To handle pagination and sorting without importing Spring classes, it introduces framework-agnostic parameter objects backed by type-safe Java enums.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in