Skip to main content

Spring Data

Spring Data eliminates the DAO boilerplate that previously required writing CRUD operations by hand. Through JpaRepository and 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:

TopicDescription
JPA Basics@Entity, @Id, @GeneratedValue, relationships (@OneToMany, @ManyToOne), fetch types.
Spring Data RepositoriesCrudRepository, JpaRepository; query methods; @Query with JPQL/native SQL.
Transactions@Transactional — propagation, isolation, readOnly, rollbackFor; self-invocation trap.
N+1 Query ProblemEAGER vs. LAZY fetch; join fetch queries; @EntityGraph as the solution.
ProjectionsInterface and DTO projections to avoid loading full entities.
Spring Data Caching@Cacheable, @CacheEvict, cache providers (Caffeine, Redis).

Learning Path

  1. JPA Basics — entity mapping and relationship annotations are the foundation; understand LAZY vs. EAGER.
  2. Spring Data Repositories — query method derivation (findByEmailAndStatus) and @Query are the two main patterns.
  3. Transactions — the self-invocation trap (this.method() bypasses the proxy) is the most common Spring bug.
  4. N+1 Problem — this is the single most common JPA performance problem; understand it deeply.
  5. Caching@Cacheable reduces database load; understand cache eviction and time-to-live.
  • Spring Framework — transaction management and AOP underpin @Transactional.
  • Databases — SQL, connection pooling, and schema migration (Flyway/Liquibase) work alongside JPA.
  • Spring Bootspring-boot-starter-data-jpa auto-configures the JPA stack.