ποΈ Spring Data & JPA / Hibernate
Core β Advanced
- Entity mapping, relationships (
@OneToMany,@ManyToOne, owning side),mappedBy - Entity lifecycle: transient β managed β detached β removed; persistence context (1st-level cache); dirty checking
- Fetching: LAZY vs EAGER, N+1 problem,
JOIN FETCH,@EntityGraph, batch fetching - Transactions:
@Transactionalpropagation (REQUIRED, REQUIRES_NEW), isolation, read-only, rollback rules - Locking: optimistic (
@Version), pessimistic (PESSIMISTIC_WRITEβSELECT β¦ FOR UPDATE,SKIP LOCKED) - Projections (interface/DTO/record), pagination (Slice vs Page, keyset)
- Specifications / Querydsl for dynamic queries
- Batch inserts (
hibernate.jdbc.batch_size, sequence ID generation) - Second-level cache (awareness), open-session-in-view (disable it)
- Migrations with Flyway (or Liquibase); expand/contract for zero-downtime deploys
- When to skip JPA: jOOQ or
JdbcClientfor complex SQL - HikariCP pool sizing
π§ͺ Labs (π’ warm-up β π‘ core β π΄ hard β β« boss)
- π’ SQL logging on; create an N+1 on workflow β steps; fix it 3 ways
- π‘ Optimistic locking on workflow publish: 50 concurrent publishes β exactly one wins
- π΄ Keyset pagination over 5M runs; compare with offset at page 10,000
- π΄ An outbox table written in the same transaction as the domain change
- β« Rewrite the heaviest query with jOOQ or
JdbcClient; compare the SQL and speed
π§ Cognitive tasks
- Predict the SQL Hibernate will emit for 5 repository methods before running them
- Symptom β hypotheses: βa save() in a loop is slow and memory growsβ
π°οΈ Orbit integration
- Workflow versions, runs, and prompts repositories in orbit-api
Go deeper
βοΈ Spring Internals Β· PostgreSQL Internals Β· π§© Enterprise & DDD Patterns
Resources
- Vlad Mihalcea: High-Performance Java Persistence + blog β
- Thorben Janssenβs blog Β· Spring Data JPA reference