Disables Hibernate's ability to use JDBC batching for inserts because the framework must execute the SQL statement immediately to retrieve the database-generated ID.
Keep transaction boundaries as tight as possible; use read-only transactions where applicable.
The second part is the heart of the book. It demonstrates how to harness the power of JPA and Hibernate without sacrificing performance—a common pitfall for many projects. Instead of using ORMs as a "black box," this section reveals how to make them work for you. Key areas include:
The book is structured to systematically build your knowledge from the foundational layers of JDBC to the high-level abstractions of JPA, Hibernate, and jOOQ. It is divided into three main parts: High-performance Java Persistence.pdf
Entities are managed. When you load 10,000 entities to process them in a loop, Hibernate keeps all of them in the First-Level Cache (Session). ✅ The Fix: session.clear() or batch processing. Don't let your memory blow up because you forgot the ORM is tracking every single object you touched.
Reusing compiled SQL statements saves database CPU cycles. Enable this feature at the JDBC driver level.
JPA and Hibernate are excellent for write-heavy, transactional processing (OLTP). However, they are poorly suited for complex reporting, analytics, or bulk data modifications. Bulk Operations Disables Hibernate's ability to use JDBC batching for
@Entity public class Post @Id @GeneratedValue(strategy = GenerationType.SEQUENCE) private Long id; @OneToMany(mappedBy = "post", cascade = CascadeType.ALL, orphanRemoval = true) private List comments = new ArrayList<>(); public void addComment(Comment comment) comments.add(comment); comment.setPost(this); public void removeComment(Comment comment) comments.remove(comment); comment.setPost(null); @Entity public class Comment @Id @GeneratedValue(strategy = GenerationType.SEQUENCE) private Long id; @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "post_id") private Post post; Use code with caution. Strategic Lazy Loading
A common mistake is assuming that a larger connection pool yields better performance. In reality, too many concurrent connections cause excessive context switching on the database server's CPU, disk thrashing, and row contention.
The book is available in both .
Enable order_inserts and order_updates ; set batch size between 20-50. Streamline SQL generation Use SEQUENCE id generation; default all relations to LAZY . Queries Eliminate N+1 issues
Creating a new database connection for every request introduces massive network and CPU overhead. Connection pools maintain a cache of active connections ready for reuse.
When your application needs to insert, update, or delete thousands of records, standard JPA methods will fail due to memory exhaustion and excessive network overhead. JDBC Batching It demonstrates how to harness the power of
Shared across sessions/nodes (e.g., via Ehcache or Hazelcast). Use it carefully for static reference data (like country codes or currency configurations).