Project
Everything covered so far, assembled into an application you can put into production.
Complete Project with Spring Boot
The previous seven lessons covered each topic in isolation. This chapter brings them together in an online bookstore application, with layered architecture, repositories, pagination, transaction management, and tests. The goal is not to showcase an exemplary architecture: it is to show where each pitfall covered earlier shows up in a real project, and which design decision neutralizes it.
Spring Data JPA adds a mechanism on top of JPA that deserves a closer look: it generates repository implementations from method names. Writing findByAuteurNomContainingIgnoreCase is enough to get the corresponding query. It is a real time saver, and just as real a trap — because nothing in a method name tells you which relationships will be loaded, so you end up with N+1 problems without ever writing a line of JPQL.
The organization used here relies on a single rule that follows from everything covered so far: an entity never crosses the boundary of the transactional layer. Entities live in the service, DTOs come out of it. This rule eliminates, in one stroke, LazyInitializationException, N+1 queries triggered from the web layer, and leaks of internal data in HTTP responses.
Comments
Comments are powered by GitHub Discussions
Sign in with GitHub to join the discussion