Spring Data and Persistence
JPA, Hibernate, transactions and the persistence mistakes that reach production.
Persistence is where object models meet relational reality. The articles in this subsection focus on the mistakes that are easy to make and expensive to discover in production.
Articles
- Spring Data JPA & HibernateHow JPA, Hibernate and Spring Data fit together: the persistence context as a unit of work and first-level cache, entity states (transient, managed, detached, removed), flush modes and dirty checking, save vs merge, repositories and derived queries, projections, open-session-in-view, batching, identifier generation, and what changed in Hibernate 7 and Jakarta Persistence 3.2.
- Mappings & fetchingMapping relationships with JPA: @OneToMany, @ManyToOne, @OneToOne and @ManyToMany, owning side and mappedBy, bidirectional helpers, cascades and orphan removal, embeddables, inheritance strategies; fetch types and their defaults, LazyInitializationException, the N+1 query problem and its fixes (fetch joins, entity graphs, batch fetching, projections), and equals/hashCode for entities.
- JPQL & Criteria APIHow to query JPA entities: JPQL syntax (joins, fetch joins, projections, aggregates, subqueries), named and native queries, parameter binding and injection safety, the type-safe Criteria API and metamodel, Spring Data Specifications and Query by Example, Querydsl, keyset pagination with Spring Data, and choosing the right tool.
- TransactionsHow Spring manages transactions: ACID, PlatformTransactionManager, how @Transactional works through proxies, rollback rules, all seven propagation behaviours with use cases, isolation levels and anomalies, read-only transactions, timeouts, optimistic and pessimistic locking, programmatic TransactionTemplate, and transactions with messaging.
- Auditing & migrationsKeeping data history and schema under control: Spring Data JPA auditing (@CreatedDate, @LastModifiedBy, AuditorAware), Hibernate Envers revision history, database triggers and CDC as alternatives; versioned schema migrations with Flyway and Liquibase in Spring Boot, naming and ordering, zero-downtime expand–contract changes, testing migrations, and running them in Kubernetes.
- Caching & RedisCaching in Spring applications: cache-aside and other patterns, @Cacheable, @CachePut, @CacheEvict and @Caching, keys and conditions, cache providers (Caffeine locally, Redis distributed), Redis configuration with TTLs and serialisation, multi-level caching, invalidation and consistency, cache stampede protection, Hibernate second-level cache, and monitoring.
Planned topics
These topics are on the roadmap and not written yet. They appear here so you can see the full scope of the section.
- Repository design