High-performance Java Persistence.pdf [upd] -
By treating Java persistence as an explicit bridge between object-oriented code and relational database logic, you eliminate performance bottlenecks before they hit production. Always complement these development strategies with continuous monitoring tools like Hibernate SQL logging, datasource proxies, and APM tools to verify the exact query footprints generated by your application.
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 .
No longer tracked (e.g., after the session closes). Removed: Scheduled for deletion upon transaction commit. 3. Advanced Mapping and Schema Design
Instead of fetching full entities with all their relationships (which are then managed by the persistence context), use to select only necessary columns. High-performance Java Persistence.pdf
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.
By default, Hibernate sends every SQL statement to the database in a separate network round-trip. This chatty behavior kills performance. Enabling JDBC Batching
Guarantees data safety for high-contention operations (e.g., inventory management, financial balances). By treating Java persistence as an explicit bridge
These settings sort the SQL statements so the database can execute them in batches, preventing interleaved statements from breaking the batching process.
Always declare relationships as FetchType.LAZY . Eager fetching ( FetchType.EAGER ) automatically loads associated entities, causing massive data transfers for fields the application might not even read.
The choice of primary key generation strategy directly impacts write performance. Vlad argues that every developer should be able
Throws an OptimisticLockException if a conflict occurs, requiring the application layer to catch the error and retry the transaction. Pessimistic Locking
@Id @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "book_seq") @SequenceGenerator(name = "book_seq", sequenceName = "book_sequence", allocationSize = 50) private Long id; Use code with caution. Bidirectional Associations