Use Bulk Updates .
for (int i = 0; i < entities.size(); i++) entityManager.persist(entities.get(i)); if (i % batchSize == 0) entityManager.flush(); entityManager.clear(); Use code with caution. Enabling Automatic JDBC Batching
Concurrency bugs can corrupt data, while aggressive locking mechanisms can paralyze application throughput. Optimistic Locking
:
The book is a fantastic starting point, but it also serves as a gateway to a much larger ecosystem of resources:
She leaned back in her chair. The PDF was still open. She clicked to a random page and saw a sentence underlined in red ink, presumably by the retired senior dev: "Performance is not a feature. It is a constraint that, when violated, breaks everything else."
If you only read Part 3 of this PDF, you will still become a better Java developer. Vlad argues that every developer should be able to read an EXPLAIN PLAN . High-performance Java Persistence.pdf
Every query executed by your Java layer must be backed by a proper indexing strategy.
High-performance persistence is not about abandoning ORMs; it is about using them correctly. An ORM is a tool for productivity, not a silver bullet that eliminates the need to understand the underlying relational database. The Golden Rule: Minimize Network Round Trips
The book is available in both .
For highly contested financial operations where consistency takes precedence over throughput (e.g., balance transfers), use pessimistic locking. This triggers an explicit database-level block (such as a SELECT ... FOR UPDATE statement).
The PDF highlights several tools and technologies that can aid in achieving high-performance Java persistence:
int updatedEntities = entityManager.createQuery( "update Post set status = :newStatus where createdOn < :date") .setParameter("newStatus", Status.OLD) .setParameter("date", LocalDate.now().minusDays(30)) .executeUpdate(); // Sends 1 SQL statement. Use Bulk Updates