Hibernate & Spring Data JPA in Depth
The definitive guide to Hibernate and Spring Data JPA. From entity mappings and relationship strategies to query optimization, caching, and the performance pitfalls that only show up under real load. Every concept backed by working code against a real PostgreSQL database.
What you'll learn
How Hibernate 7 and Spring Data JPA work together at the contract level
Entity lifecycle, dirty checking, and the first-level cache in depth
Associations: every strategy from @OneToMany to bidirectional ManyToMany
JPQL, native SQL, dynamic queries, and the full Spring Data query spectrum
The N+1 problem: every detection technique and every fix
Optimistic locking with @Version and pessimistic locking under concurrent load
Fetch strategies: LAZY, EAGER, EntityGraph, and batch fetching compared honestly
Second-level caching with real provider configuration for production
Multi-tenancy: schema isolation, discriminator columns, and separate databases
Auditing with Hibernate Envers and custom interceptors
Table of Contents
Foundation
- 01 JPA, Hibernate 7, and the Contract
- 02 The Persistence Context
- 03 Transactions and the Unit of Work
- 04 Hibernate 7 Internals
Mapping
- 05 Entity Mapping Deep Dive
- 06 Associations — Every Variant
- 07 Inheritance Strategies
- 08 Identifiers, Natural IDs, and Composite Keys
Querying
- 09 Repository Internals and Custom Implementations
- 10 JPQL, Native Queries, and @Query
- 11 Dynamic Queries — Specifications, QueryDSL, and Beyond
- 12 Projections, DTOs, and Result Mapping
Locking and Fetch
- 13 Optimistic Locking
- 14 Pessimistic Locking
- 15 Fetch Strategies — LAZY, EAGER, EntityGraph, and Batch Fetching
- 16 The N+1 Problem — Diagnosis and All the Fixes
Advanced Patterns
- 17 Batch Processing, Streaming, and StatelessSession
- 18 Second-Level Cache — Architecture, Providers, and Production
- 19 Schema Management — Flyway, hbm2ddl, and Validation
- 20 Multi-tenancy — Schema, Discriminator, and Separate Database
Production
- 21 Auditing and Hibernate Envers
- 22 Interceptors, Event Listeners, and Row-Level Filters
- 23 Advanced HQL — Window Functions, CTEs, and Hibernate 7 Extensions
- 24 Custom Types — UserType 2.0, JavaType, and JdbcType
- 25 Hibernate Search — Full-Text Search with Lucene and Elasticsearch
- 26 Reactive Persistence — Hibernate Reactive and Spring Data R2DBC
- 27 Observability — Metrics, Tracing, and Slow Query Detection
- 28 Testing — @DataJpaTest, Testcontainers, and Repository Testing