High-Performance Java Persistence
High-Performance Java Persistence
Get the most out of your persistence layer
About the Book
For the ultimate learning experience, you should definitely enroll in my
This book is a journey into Java data access performance tuning. From connection management, to batch updates, fetch sizes and concurrency control mechanisms, it unravels the inner workings of the most common Java data access frameworks.
The first part aims to reduce the gap between application developers and database administrators. For this reason, it covers both JDBC and the database fundamentals that are of paramount importance when reducing transaction response times. In this first part, you'll learn about connection management, batch updates, statement caching, result set fetching and database transactions.
The second part demonstrates how you can take advantage of JPA and Hibernate without compromising application performance. In this second part, you'll learn about the most efficient Hibernate mappings (basic types, associations, inheritance), fetching best practices, caching and concurrency control mechanisms.
The third part is dedicated to jOOQ and its powerful type-safe querying capabilities, like window functions, common table expressions, UPSERT, stored procedures and database functions.
25% discount - Pack of 3
This package is for 3 copies of the "High-Performance Java Persistence" at a 25% discount.
Java Champion, founder and CEO of Data Geekery GmbH, the company behind jOOQ
This book is a must-read for everyone aiming to push their relational databases to the limit with their Java application.
Java Champion, creator of Byte Buddy
There is no resource that better summarizes the performance implications of using JDBC, either directly or via JPA and Hibernate. If you are talking to a database on the JVM, add this book to your reading shelf.
Java Champion, Developer Advocate at Lightbend
Object to database mapping is one of the core requirements in many Java EE related projects. And the available frameworks make it easy for their users to get started. But as soon as you hit particular requirements around distributed transactions or performance you realise how much database and framework knowledge is required to implement them. Vlad made his insane experience available in an easy-to-read book. If you are dealing with JPA or Hibernate, this book is a must read.
Java Champion, co-creator of AllCraft.io
Writing a book is difficult, but writing a book about performance and persistence is a real challenge. If you want to understand how locking, sharding, replication, database concurrency control work, then this book is for you. Vlad gives you plenty of tips and tricks on Hibernate, helping you diagnose your performance issues (e.g. mapping, fetching, or caching). I learn a lot by reading his book and I highly recommend it if you use relational databases and ORM tools such as Hibernate.
Owner of Baeldung, Spring courses author
Good books on persistence are few and far between. This is something else - it's deeply researched but also entirely practical. I'm basically using it as a reference for everything SQL. Plus, the transaction chapter is a must read.
Software engineer & enthusiast, creator of Vibur DBCP
This book is a highly recommended resource for every developer who is serious about learning and mastering the difficult topic of designing and implementing high performance Java database applications. The book covers in detail the performance aspect of the plain JDBC and Hibernate programming, explains the theoretical and practical implications of the database transactions, and discusses some rare topics such as the database connection pool sizing and statement caching.
- The database server and the connectivity layer
The application data access layer
- The ORM framework
- The native query builder framework
I JDBC and Database Essentials
1. Performance and Scaling
- 1.1 Response time and throughput
- 1.2 Database connections boundaries
1.3 Scaling up and scaling out
- 1.3.1 Master-Slave replication
- 1.3.2 Multi-Master replication
- 1.3.3 Sharding
2. JDBC Connection Management
- 2.1 DriverManager
- 2.2.1 Why is pooling so much faster?
- 2.3 Queuing theory capacity planning
2.4 Practical database connection provisioning
2.4.1 A real-life connection pool monitoring example
- 126.96.36.199 Concurrent connection request count metric
- 188.8.131.52 Concurrent connection count metric
- 184.108.40.206 Maximum pool size metric
- 220.127.116.11 Connection acquisition time metric
- 18.104.22.168 Retry attempts metric
- 22.214.171.124 Overall connection acquisition time metric
- 126.96.36.199 Connection lease time metric
- 2.4.1 A real-life connection pool monitoring example
3. Batch Updates
- 3.1 Batching Statements
3.2 Batching PreparedStatements
- 3.2.1 Choosing the right batch size
- 3.2.2 Bulk processing
3.3 Retrieving auto-generated keys
- 3.3.1 Sequences to the rescue
4. Statement Caching
4.1 Statement lifecycle
- 4.1.1 Parser
- 188.8.131.52 Execution plan visualization
- 4.1.3 Executor
- 4.2 Caching performance gain
4.3 Server-side statement caching
- 4.3.1 Bind-sensitive execution plans
- 4.4 Client-side statement caching
- 4.1 Statement lifecycle
5. ResultSet Fetching
- 5.1 ResultSet scrollability
- 5.2 ResultSet changeability
- 5.3 ResultSet holdability
- 5.4 Fetching size
5.5 ResultSet size
5.5.1 Too many rows
- 184.108.40.206 SQL limit clause
- 220.127.116.11 JDBC max rows
- 18.104.22.168 Less is more
- 5.5.2 Too many columns
- 5.5.1 Too many rows
- 6.1 Atomicity
- 6.2 Consistency
6.3.1 Concurrency control
- 22.214.171.124 Two-phase locking
- 126.96.36.199 Multi-Version Concurrency Control
- 188.8.131.52 Dirty write
- 184.108.40.206 Dirty read
- 220.127.116.11 Non-repeatable read
- 18.104.22.168 Phantom read
- 22.214.171.124 Read skew
- 126.96.36.199 Write skew
- 188.8.131.52 Lost update
6.3.3 Isolation levels
- 184.108.40.206 Read Uncommitted
- 220.127.116.11 Read Committed
- 18.104.22.168 Repeatable Read
- 22.214.171.124 Serializable
- 6.3.1 Concurrency control
- 6.4 Durability
6.5 Read-only transactions
- 6.5.1 Read-only transaction routing
6.6 Transaction boundaries
6.6.1 Distributed transactions
- 126.96.36.199 Two-phase commit
- 6.6.2 Declarative transactions
- 6.6.1 Distributed transactions
6.7 Application-level transactions
6.7.1 Pessimistic and optimistic locking
- 188.8.131.52 Pessimistic locking
- 184.108.40.206 Optimistic locking
- 6.7.1 Pessimistic and optimistic locking
- 1. Performance and Scaling
II JPA and Hibernate
7. Why JPA and Hibernate matter
- 7.1 The impedance mismatch
- 7.2 JPA vs. Hibernate
- 7.3 Schema ownership
- 7.4 Entity state transitions
- 7.5 Write-based optimizations
- 7.6 Read-based optimizations
- 7.7 Wrap-up
8. Connection Management and Monitoring
- 8.1 JPA connection management
8.2 Hibernate connection providers
- 8.2.1 DriverManagerConnectionProvider
- 8.2.2 C3P0ConnectionProvider
- 8.2.3 HikariCPConnectionProvider
- 8.2.4 DatasourceConnectionProvider
- 8.2.5 Connection release modes
8.3 Monitoring connections
8.3.1 Hibernate statistics
- 220.127.116.11 Customizing statistics
- 8.3.1 Hibernate statistics
8.4 Statement logging
- 8.4.1 Statement formatting
- 8.4.2 Statement-level comments
8.4.3 Logging parameters
- 18.104.22.168 DataSource-proxy
- 22.214.171.124 P6Spy
9. Mapping Types and Identifiers
- 9.1.1 Primitive types
- 9.1.2 String types
- 9.1.3 Date and Time types
- 9.1.4 Numeric types
- 9.1.5 Binary types
- 9.1.6 UUID types
- 9.1.7 Other types
- 9.1.8 Custom types
9.2.1 UUID identifiers
- 126.96.36.199 The assigned generator
9.2.2 The legacy UUID generator
- 188.8.131.52 The newer UUID generator
9.2.3 Numerical identifiers
- 184.108.40.206 Identity generator
- 220.127.116.11 Sequence generator
- 18.104.22.168 Table generator
- 22.214.171.124.1 The hi/lo algorithm
- 126.96.36.199.2 The default sequence identifier generator
- 188.8.131.52.3 The default table identifier generator
- 184.108.40.206.4 The pooled optimizer
- 220.127.116.11.5 The pooled-lo optimizer
18.104.22.168 Optimizer gain
- 22.214.171.124.1 Sequence generator performance gain
- 126.96.36.199.2 Table generator performance gain
- 188.8.131.52 Identifier generator performance
- 9.2.1 UUID identifiers
- 9.1 Types
- 10.1 Relationship types
- 10.2 @ManyToOne
- 10.3.1 Bidirectional @OneToMany
- 10.3.2 Unidirectional @OneToMany
- 10.3.3 Ordered unidirectional @OneToMany
- 10.3.4 @OneToMany with @JoinColumn
- 10.3.5 Unidirectional @OneToMany Set
- 10.4.1 @ElementCollection List
- 10.4.2 @ElementCollection Set
- 10.5.1 Unidirectional @OneToOne
- 10.5.2 Bidirectional @OneToOne
- 10.6.1 Unidirectional @ManyToMany List
- 10.6.2 Unidirectional @ManyToMany Set
- 10.6.3 Bidirectional @ManyToMany
- 10.6.4 The @OneToMany alternative
10.7 Hypersistence Optimizer
- 10.7.1 Testimonials
11.1 Single table
- 11.1.1 Data integrity constraints
- 11.2 Join table
- 11.3 Table-per-class
- 11.4 Mapped superclass
- 11.1 Single table
- 12.1 Flush modes
12.2 Events and the action queue
- 12.2.1 Flush operation order
12.3 Dirty Checking
12.3.1 The default dirty checking mechanism
- 184.108.40.206 Controlling the Persistence Context size
- 12.3.2 Bytecode enhancement
- 12.3.1 The default dirty checking mechanism
- 13.1 Batching insert statements
- 13.2 Batching update statements
- 13.3 Batching delete statements
14.1 DTO projection
- 14.1.1 DTO projection pagination
- 14.1.2 Native query DTO projection
- 14.2 Query fetch size
14.3 Fetching entities
14.3.1 Direct fetching
- 220.127.116.11 Fetching a Proxy reference
- 18.104.22.168 Natural identifier fetching
- 14.3.2 Query fetching
14.3.3 Fetching associations
- 22.214.171.124 FetchType.EAGER
- 126.96.36.199.1 The N+1 query problem
- 188.8.131.52.2 How to catch N+1 query problems during testing
- 184.108.40.206.3 LazyInitializationException
- 220.127.116.11.4 The Open Session in View Anti-Pattern
- 18.104.22.168.5 Temporary Session Lazy Loading Anti-Pattern
- 22.214.171.124 Associations and pagination
- 14.3.4 Attribute lazy fetching
- 14.3.5 Fetching subentities
- 14.3.1 Direct fetching
- 14.4 Entity reference deduplication
- 14.5 Query plan cache
- 14.1 DTO projection
- 15.1 Caching flavors
15.2 Cache synchronization strategies
- 15.2.1 Cache-aside
- 15.2.2 Read-through
- 15.2.3 Write-invalidate
- 15.2.4 Write-through
- 15.2.5 Write-behind
- 15.3 Database caching
15.4 Application-level caching
- 15.4.1 Entity aggregates
- 15.4.2 Distributed key-value stores
- 15.4.3 Cache synchronization patterns
- 15.4.4 Synchronous updates
15.4.5 Asynchronous updates
- 126.96.36.199 Change data capture
15.5 Second-level caching
- 15.5.1 Enabling the second-level cache
- 15.5.2 Entity cache loading flow
15.5.3 Entity cache entry
- 188.8.131.52 Entity reference cache store
- 15.5.4 Collection cache entry
- 15.5.5 Query cache entry
15.5.6 Cache concurrency strategies
- 184.108.40.206.1 Inserting READ_ONLY cache entries
- 220.127.116.11.2 Updating READ_ONLY cache entries
- 18.104.22.168.3 Deleting READ_ONLY cache entries
- 22.214.171.124.1 Inserting NONSTRICT_READ_WRITE cache entries
- 126.96.36.199.2 Updating NONSTRICT_READ_WRITE cache entries
- 188.8.131.52.3 Risk of inconsistencies
- 184.108.40.206.4 Deleting NONSTRICT_READ_WRITE cache entries
- 220.127.116.11.1 Inserting READ_WRITE cache entries
- 18.104.22.168.2 Updating READ_WRITE cache entries
- 22.214.171.124.3 Deleting READ_WRITE cache entries
- 126.96.36.199.4 Soft locking concurrency control
- 188.8.131.52.1 XA_Strict mode
- 184.108.40.206.2 XA mode
- 220.127.116.11.3 Inserting TRANSACTIONAL cache entries
- 18.104.22.168.4 Updating TRANSACTIONAL cache entries
- 22.214.171.124.5 Deleting TRANSACTIONAL cache entries
- 126.96.36.199 READ_ONLY
15.5.7 Query cache strategy
- 188.8.131.52 Tablespace query cache invalidation
- 184.108.40.206 Native SQL statement query cache invalidation
16. Concurrency Control
16.1 Hibernate optimistic locking
16.1.1 The implicit optimistic locking mechanism
- 220.127.116.11 Resolving optimistic locking conflicts
- 18.104.22.168 Splitting entities
22.214.171.124 Versionless optimistic locking
- 126.96.36.199.1 OptimisticLockType.DIRTY update caveat
- 16.1.1 The implicit optimistic locking mechanism
16.2 The explicit locking mechanism
16.2.1 PESSIMISTIC_READ and PESSIMISTIC_WRITE
- 188.8.131.52 Lock scope
- 184.108.40.206 Lock timeout
- 220.127.116.11 Inconsistency risk
- 16.2.3 LockModeType.OPTIMISTIC_FORCE_INCREMENT
- 16.2.4 LockModeType.PESSIMISTIC_FORCE_INCREMENT
- 16.2.1 PESSIMISTIC_READ and PESSIMISTIC_WRITE
- 16.1 Hibernate optimistic locking
- 7. Why JPA and Hibernate matter
17. Why jOOQ matters
- 17.1 How jOOQ works
- 17.2 DML statements
- 17.3 Java-based schema
- 17.4.1 Oracle
- 17.4.2 SQL Server
- 17.4.3 PostgreSQL
- 17.4.4 MySQL
- 17.5 Batch updates
- 17.6 Inlining bind parameters
- 17.7 Complex queries
- 17.8 Stored procedures and functions
- 17.9 Streaming
- 17.10 Keyset pagination
- 17. Why jOOQ matters
The Leanpub 45-day 100% Happiness Guarantee
Within 45 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.
See full terms
Free Updates. DRM Free.
If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).
Most Leanpub books are available in PDF (for computers), EPUB (for phones and tablets) and MOBI (for Kindle). The formats that a book includes are shown at the top right corner of this page.
Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.
C++ Best PracticesJason Turner
Level up your C++, get the tools working for you, eliminate common problems, and move on to more exciting things!
Continuous Delivery PipelinesDave Farley
This practical handbook provides a step-by-step guide for you to get the best continuous delivery pipeline for your software.
OpenIntro StatisticsDavid Diez, Christopher Barr, Mine Cetinkaya-Rundel, and OpenIntro
A complete foundation for Statistics, also serving as a foundation for Data Science.
Leanpub revenue supports OpenIntro (US-based nonprofit) so we can provide free desk copies to teachers interested in using OpenIntro Statistics in the classroom and expand the project to support free textbooks in other subjects.
More resources: openintro.org.
C++20 is the next big C++ standard after C++11. As C++11 did it, C++20 changes the way we program modern C++. This change is, in particular, due to the big four of C++20: ranges, coroutines, concepts, and modules.
The book is almost daily updated. These incremental updates ease my interaction with the proofreaders.
Atomic KotlinBruce Eckel and Svetlana Isakova
For both beginning and experienced programmers! From the author of the multi-award-winning Thinking in C++ and Thinking in Java together with a member of the Kotlin language team comes a book that breaks the concepts into small, easy-to-digest "atoms," along with exercises supported by hints and solutions directly inside IntelliJ IDEA!
Introductory Statistics with Randomization and SimulationMine Cetinkaya-Rundel, Christopher Barr, OpenIntro, and David Diez
A complete foundation for Statistics, also serving as a foundation for Data Science, that introduces inference using randomization and simulation while covering traditional methods.
Leanpub revenue supports OpenIntro, so we can provide free desk copies to teachers interested in using our books in the classroom.
More resources: openintro.org.
Ansible for DevOpsJeff Geerling
Ansible is a simple, but powerful, server and configuration management tool. Learn to use Ansible effectively, whether you manage one server—or thousands.
Java OOP Done RightAlan Mellor
Object Oriented Programming is still a great way to create clean, maintainable code. But only if you use it right.
This book gives you 25 years of OO best practice, ready to use.
You'll learn to design objects behaviour-first, use TDD to help, then confidently apply Design Patterns, SOLID principles and Refactoring to make clean, crafted code.
Introducing EventStormingAlberto Brandolini
The deepest tutorial and explanation about EventStorming, straight from the inventor.
Discrete Mathematics for Computer ScienceAlexander Shen, Alexander S. Kulikov, Vladimir Podolskii, and Aleksandr Golovnev
This book supplements the DM for CS Specialization at Coursera and contains many interactive puzzles, autograded quizzes, and code snippets. They are intended to help you to discover important ideas in discrete mathematics on your own. By purchasing the book, you will get all updates of the book free of charge when they are released.
Software Architecture for Developers: Volumes 1 & 2 - Technical leadership and communication
2 Books"Software Architecture for Developers" is a practical and pragmatic guide to modern, lightweight software architecture, specifically aimed at developers. You'll learn:The essence of software architecture.Why the software architecture role should include coding, coaching and collaboration.The things that you really need to think about before...
CCIE Service Provider Ultimate Study Bundle
2 BooksPiotr Jablonski, Lukasz Bromirski, and Nick Russo have joined forces to deliver the only CCIE Service Provider training resource you'll ever need. This bundle contains a detailed and challenging collection of workbook labs, plus an extensively detailed technical reference guide. All of us have earned the CCIE Service Provider certification...
Cisco CCNA 200-301 Complet
4 BooksCe lot comprend les quatre volumes du guide préparation à l'examen de certification Cisco CCNA 200-301.
Modern C++ by Nicolai Josuttis
CCDE Practical Studies (All labs)
3 BooksCCDE lab
"The C++ Standard Library" and "Concurrency with Modern C++"
2 BooksGet my books "The C++ Standard Library" and "Concurrency with Modern C++" in a bundle. The first book gives you the details you should know about the C++ standard library; the second one dives deeper into concurrency with modern C++. In sum, you get more than 600 pages full of modern C++ and about 250 source files presenting the standard library...
2 BooksDocker and Kubernetes are taking the world by storm! These books will get you up-to-speed fast! Docker Deep Dive is over 400 pages long, and covers all objectives on the Docker Certified Associate exam.The Kubernetes Book includes everything you need to get up and running with Kubernetes!
The Future of Digital Health
6 BooksWe put together the most popular books from The Medical Futurist to provide a clear picture about the major trends shaping the future of medicine and healthcare. Digital health technologies, artificial intelligence, the future of 20 medical specialties, big pharma, data privacy and how technology giants such as Amazon or Google want to conquer...
Django for Beginners/APIs/Professionals
Linux Administration Complet
4 BooksCe lot comprend les quatre volumes du Guide Linux Administration :Linux Administration, Volume 1, Administration fondamentale : Guide pratique de préparation aux examens de certification LPIC 1, Linux Essentials, RHCSA et LFCS. Administration fondamentale. Introduction à Linux. Le Shell. Traitement du texte. Arborescence de fichiers. Sécurité...