High performance java persistence book

About the Book

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.

Share this book

Categories

  • Software
  • Java
  • Databases
  • MySQL
  • Oracle
  • PostgreSQL
  • SQL Server
  • Software Engineering
  • Software Architecture

Feedback

About the Author

Vlad Mihalcea is a Hibernate Developer Advocate working for Red Hat, passionate about concurrency challenges, high-performance enterprise solutions and online transaction processing.

Whenever he finds something interesting, he likes to share it on his personal blog. He believes in Open Source Software and he thinks every developer should get involved, one way or the other.

If he doesn’t find a suitable tool for a job, he takes initiative and starts a new open source project, like FlexyPool.

Packages

The Book
25% discount — Pack of 3

This package is for 3 copies of the «High-Performance Java Persistence» at a 25% discount.

Reader Testimonials

Lukas Eder

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.

Rafael Winterhalter

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.

Markus Eisele

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.

Читайте также:  Поиск наибольшего делителя числа python
Antonio Goncalves

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.

Eugen Paraschiv

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.

Simeon Malchev

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.

Table of Contents

    • Preface
      • The database server and the connectivity layer
      • The application data access layer
        • The ORM framework
        • The native query builder framework
        • Testimonials
        • 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.1 DriverManager
            • 2.2 DataSource
              • 2.2.1 Why is pooling so much faster?
              • 2.4.1 A real-life connection pool monitoring example
                • 2.4.1.1 Concurrent connection request count metric
                • 2.4.1.2 Concurrent connection count metric
                • 2.4.1.3 Maximum pool size metric
                • 2.4.1.4 Connection acquisition time metric
                • 2.4.1.5 Retry attempts metric
                • 2.4.1.6 Overall connection acquisition time metric
                • 2.4.1.7 Connection lease time metric
                • 3.1 Batching Statements
                • 3.2 Batching PreparedStatements
                  • 3.2.1 Choosing the right batch size
                  • 3.2.2 Bulk processing
                  • 3.3.1 Sequences to the rescue
                  • 4.1 Statement lifecycle
                    • 4.1.1 Parser
                    • 4.1.2 Optimizer
                      • 4.1.2.1 Execution plan visualization
                      • 4.3.1 Bind-sensitive execution plans
                      • 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
                          • 5.5.1.1 SQL limit clause
                          • 5.5.1.2 JDBC max rows
                          • 5.5.1.3 Less is more
                          • 6.1 Atomicity
                          • 6.2 Consistency
                          • 6.3 Isolation
                            • 6.3.1 Concurrency control
                              • 6.3.1.1 Two-phase locking
                              • 6.3.1.2 Multi-Version Concurrency Control
                              • 6.3.2.1 Dirty write
                              • 6.3.2.2 Dirty read
                              • 6.3.2.3 Non-repeatable read
                              • 6.3.2.4 Phantom read
                              • 6.3.2.5 Read skew
                              • 6.3.2.6 Write skew
                              • 6.3.2.7 Lost update
                              • 6.3.3.1 Read Uncommitted
                              • 6.3.3.2 Read Committed
                              • 6.3.3.3 Repeatable Read
                              • 6.3.3.4 Serializable
                              • 6.5.1 Read-only transaction routing
                              • 6.6.1 Distributed transactions
                                • 6.6.1.1 Two-phase commit
                                • 6.7.1 Pessimistic and optimistic locking
                                  • 6.7.1.1 Pessimistic locking
                                  • 6.7.1.2 Optimistic locking
                                  • 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.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.1 Hibernate statistics
                                        • 8.3.1.1 Customizing statistics
                                        • 8.4.1 Statement formatting
                                        • 8.4.2 Statement-level comments
                                        • 8.4.3 Logging parameters
                                          • 8.4.3.1 DataSource-proxy
                                          • 8.4.3.2 P6Spy
                                          • 9.1 Types
                                            • 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
                                              • 9.2.1.1 The assigned generator
                                              • 9.2.2.1 The newer UUID generator
                                              • 9.2.3.1 Identity generator
                                              • 9.2.3.2 Sequence generator
                                              • 9.2.3.3 Table generator
                                              • 9.2.3.4 Optimizers
                                                • 9.2.3.4.1 The hi/lo algorithm
                                                • 9.2.3.4.2 The default sequence identifier generator
                                                • 9.2.3.4.3 The default table identifier generator
                                                • 9.2.3.4.4 The pooled optimizer
                                                • 9.2.3.4.5 The pooled-lo optimizer
                                                • 9.2.3.5.1 Sequence generator performance gain
                                                • 9.2.3.5.2 Table generator performance gain
                                                • 10.1 Relationship types
                                                • 10.2 @ManyToOne
                                                • 10.3 @OneToMany
                                                  • 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.1 Testimonials
                                                  • 11.1 Single table
                                                    • 11.1.1 Data integrity constraints
                                                    • 12.1 Flush modes
                                                    • 12.2 Events and the action queue
                                                      • 12.2.1 Flush operation order
                                                      • 12.3.1 The default dirty checking mechanism
                                                        • 12.3.1.1 Controlling the Persistence Context size
                                                        • 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.3.1 Direct fetching
                                                            • 14.3.1.1 Fetching a Proxy reference
                                                            • 14.3.1.2 Natural identifier fetching
                                                            • 14.3.3.1 FetchType.EAGER
                                                            • 14.3.3.2 FetchType.LAZY
                                                              • 14.3.3.2.1 The N+1 query problem
                                                              • 14.3.3.2.2 How to catch N+1 query problems during testing
                                                              • 14.3.3.2.3 LazyInitializationException
                                                              • 14.3.3.2.4 The Open Session in View Anti-Pattern
                                                              • 14.3.3.2.5 Temporary Session Lazy Loading Anti-Pattern
                                                              • 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.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
                                                                  • 15.4.5.1 Change data capture
                                                                  • 15.5.1 Enabling the second-level cache
                                                                  • 15.5.2 Entity cache loading flow
                                                                  • 15.5.3 Entity cache entry
                                                                    • 15.5.3.1 Entity reference cache store
                                                                    • 15.5.6.1 READ_ONLY
                                                                      • 15.5.6.1.1 Inserting READ_ONLY cache entries
                                                                      • 15.5.6.1.2 Updating READ_ONLY cache entries
                                                                      • 15.5.6.1.3 Deleting READ_ONLY cache entries
                                                                      • 15.5.6.2.1 Inserting NONSTRICT_READ_WRITE cache entries
                                                                      • 15.5.6.2.2 Updating NONSTRICT_READ_WRITE cache entries
                                                                      • 15.5.6.2.3 Risk of inconsistencies
                                                                      • 15.5.6.2.4 Deleting NONSTRICT_READ_WRITE cache entries
                                                                      • 15.5.6.3.1 Inserting READ_WRITE cache entries
                                                                      • 15.5.6.3.2 Updating READ_WRITE cache entries
                                                                      • 15.5.6.3.3 Deleting READ_WRITE cache entries
                                                                      • 15.5.6.3.4 Soft locking concurrency control
                                                                      • 15.5.6.4.1 XA_Strict mode
                                                                      • 15.5.6.4.2 XA mode
                                                                      • 15.5.6.4.3 Inserting TRANSACTIONAL cache entries
                                                                      • 15.5.6.4.4 Updating TRANSACTIONAL cache entries
                                                                      • 15.5.6.4.5 Deleting TRANSACTIONAL cache entries
                                                                      • 15.5.7.1 Tablespace query cache invalidation
                                                                      • 15.5.7.2 Native SQL statement query cache invalidation
                                                                      • 16.1 Hibernate optimistic locking
                                                                        • 16.1.1 The implicit optimistic locking mechanism
                                                                          • 16.1.1.1 Resolving optimistic locking conflicts
                                                                          • 16.1.1.2 Splitting entities
                                                                          • 16.1.1.3 Versionless optimistic locking
                                                                            • 16.1.1.3.1 OptimisticLockType.DIRTY update caveat
                                                                            • 16.2.1 PESSIMISTIC_READ and PESSIMISTIC_WRITE
                                                                              • 16.2.1.1 Lock scope
                                                                              • 16.2.1.2 Lock timeout
                                                                              • 16.2.2.1 Inconsistency risk
                                                                              • 17. Why jOOQ matters
                                                                                • 17.1 How jOOQ works
                                                                                • 17.2 DML statements
                                                                                • 17.3 Java-based schema
                                                                                • 17.4 Upsert
                                                                                  • 17.4.1 Oracle
                                                                                  • 17.4.2 SQL Server
                                                                                  • 17.4.3 PostgreSQL
                                                                                  • 17.4.4 MySQL

                                                                                  The Leanpub 60-day 100% Happiness Guarantee

                                                                                  Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

                                                                                  80% Royalties. Earn $16 on a $20 book.

                                                                                  We pay 80% royalties. That’s not a typo: you earn $16 on a $20 sale. If we sell 5000 non-refunded copies of your book or course for $20, you’ll earn $80,000.

                                                                                  (Yes, some authors have already earned much more than that on Leanpub.)

                                                                                  In fact, authors have earned over $12 million writing, publishing and selling on Leanpub.

                                                                                  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) and EPUB (for phones, tablets and 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.

                                                                                  Write and Publish on Leanpub

                                                                                  You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

                                                                                  Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

                                                                                  Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

                                                                                  Publish Early, Publish Often

                                                                                  Источник

Оцените статью