Spring Data
Spring Data eliminates the DAO boilerplate that previously required writing CRUD operations by hand. Through
JpaRepositoryand query-method derivation, you get database access with almost zero implementation code. The important things to master are the N+1 query problem, transaction propagation rules, and when to step outside Spring Data's conventions for complex queries.
What You'll Find Here
Notes are being added. Planned topics:
| Topic | Description |
|---|---|
| JPA Basics | @Entity, @Id, @GeneratedValue, relationships (@OneToMany, @ManyToOne), fetch types. |
| Spring Data Repositories | CrudRepository, JpaRepository; query methods; @Query with JPQL/native SQL. |
| Transactions | @Transactional — propagation, isolation, readOnly, rollbackFor; self-invocation trap. |
| N+1 Query Problem | EAGER vs. LAZY fetch; join fetch queries; @EntityGraph as the solution. |
| Projections | Interface and DTO projections to avoid loading full entities. |
| Spring Data Caching | @Cacheable, @CacheEvict, cache providers (Caffeine, Redis). |
Learning Path
- JPA Basics — entity mapping and relationship annotations are the foundation; understand
LAZYvs.EAGER. - Spring Data Repositories — query method derivation (
findByEmailAndStatus) and@Queryare the two main patterns. - Transactions — the self-invocation trap (
this.method()bypasses the proxy) is the most common Spring bug. - N+1 Problem — this is the single most common JPA performance problem; understand it deeply.
- Caching —
@Cacheablereduces database load; understand cache eviction and time-to-live.
Related Domains
- Spring Framework — transaction management and AOP underpin
@Transactional. - Databases — SQL, connection pooling, and schema migration (Flyway/Liquibase) work alongside JPA.
- Spring Boot —
spring-boot-starter-data-jpaauto-configures the JPA stack.