High-performance Java Persistence.pdf
[ Application Thread ] │ ▼ ┌──────────────────────────────────────┐ │ First-Level Cache (Session/EM) │ ── (Scoped to current transaction) └──────────────────────────────────────┘ │ (Cache Miss) ▼ ┌──────────────────────────────────────┐ │ Second-Level Cache (2L Cache) │ ── (Shared across application clusters) └──────────────────────────────────────┘ │ (Cache Miss) ▼ ┌──────────────────────────────────────┐ │ Relational Database │ └──────────────────────────────────────┘ First-Level Cache (Persistence Context)
Mark read-only transactions explicitly using @Transactional(readOnly = true) . This allows Spring and Hibernate to apply optimizations, such as disabling dirty checking and routing queries to database replicas. High-performance Java Persistence.pdf
For many Java developers, Hibernate (and JPA) is a double-edged sword. On one hand, it abstracts away the tedious JDBC boilerplate and allows us to navigate a database using an object-oriented paradigm. On the other hand, it is notorious for being a "black box" that can silently cripple application performance if not handled with care. On one hand, it abstracts away the tedious


