High-Performance Java Persistence
Get the most out of your persistence layer
A high-performance data access layer must resonate with the underlying database system. Knowing the inner workings of a relational database and the data access frameworks in use can make the difference between a high-performance enterprise application and one that barely crawls.
About
About the Book
For the ultimate learning experience, you should definitely enroll in my
High-Performance Java Persistence video courses.
If you're interested in a print copy, then check out the Paperback version on Amazon, Amazon.co.uk, Amazon.de or Amazon.fr.
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.
Categories
Feedback
Packages
Pick Your Package
All packages include the ebook in the following formats: PDF, EPUB, and Web
The Book
Minimum price
Suggested price$34.95$29.95
25% discount - Pack of 3
Minimum price
Suggested price$74.95This package is for 3 copies of the "High-Performance Java Persistence" at a 25% discount.
$64.95
Author
About the Author
Vlad Mihalcea
Vlad Mihalcea is a Java Champion, one of the top Hibernate ORM project committers, passionate about concurrency challenges, high-performance enterprise solutions, and online transaction processing.
He's been answering thousands of questions about Hibernate and JPA on StackOverflow for which he's got gold badges for Hibernate, Java, and JPA tags.
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.
Contents
Table of Contents
Preface
- The database server and the connectivity layer
- The application data access layer
- The ORM framework
- The native query builder framework
- About database performance benchmarks
- Video Course
- Testimonials
- IJDBC and Database Essentials
1.Performance and Scaling
- 1.1Response time and throughput
- 1.2Database connections boundaries
- 1.3Scaling up and scaling out
- 1.3.1Master-Slave replication
- 1.3.2Multi-Master replication
- 1.3.3Sharding
- MySQL cluster auto-sharding
- Little’s Law
2.JDBC Connection Management
- 2.1DriverManager
- Oracle mainframe legacy
- 2.2DataSource
- Oracle XE connection handling limitation
- 2.2.1Why is pooling so much faster?
- 2.3Queuing theory capacity planning
- 2.4Practical database connection provisioning
- 2.4.1A real-life connection pool monitoring example
- 2.4.1.1Concurrent connection request count metric
- 2.4.1.2Concurrent connection count metric
- 2.4.1.3Maximum pool size metric
- 2.4.1.4Connection acquisition time metric
- 2.4.1.5Retry attempts metric
- 2.4.1.6Overall connection acquisition time metric
- 2.4.1.7Connection lease time metric
3.Batch Updates
- 3.1Batching Statements
- Oracle
- MySQL
- 3.2Batching PreparedStatements
- SQL injection
- 3.2.1Choosing the right batch size
- 3.2.2Bulk processing
- Long-running transaction caveats
- 3.3Retrieving auto-generated keys
- Oracle
- SQL Server
- PostgreSQL
- MySQL
- Oracle auto-generated key retrieval gotcha
- 3.3.1Sequences to the rescue
- Oracle
- SQL Server
- PostgreSQL
- Optimizing sequence calls
4.Statement Caching
- 4.1Statement lifecycle
- 4.1.1Parser
- 4.1.2Optimizer
- 4.1.2.1Execution plan visualization
- Oracle
- PostgreSQL
- SQL Server
- MySQL
- MySQL
- 4.1.3Executor
- 4.2Caching performance gain
- 4.3Server-side statement caching
- Forced Parameterization
- Oracle
- SQL Server
- 4.3.1Bind-sensitive execution plans
- Oracle
- Bind peeking
- SQL Server
- PostgreSQL
- MySQL
- 4.4Client-side statement caching
- Oracle implicit statement caching
- Oracle explicit statement caching
- SQL Server
- PostgreSQL
- MySQL
5.ResultSet Fetching
- 5.1ResultSet scrollability
- Oracle
- SQL Server
- PostgreSQL
- MySQL
- 5.2ResultSet changeability
- 5.3ResultSet holdability
- Oracle
- SQL Server
- PostgreSQL
- MySQL
- 5.4Fetching size
- Oracle
- SQL Server
- PostgreSQL
- MySQL
- 5.5ResultSet size
- 5.5.1Too many rows
- 5.5.1.1SQL limit clause
- SQL:2008
- Oracle
- SQL Server
- PostgreSQL and MySQL
- 5.5.1.2JDBC max rows
- Oracle
- SQL Server
- PostgreSQL
- MySQL
- 5.5.1.3Less is more
- 5.5.2Too many columns
6.Transactions
- 6.1Atomicity
- Write-write conflicts
- Oracle
- SQL Server
- PostgreSQL
- MySQL
- 6.2Consistency
- MySQL
- Consistency as in CAP Theorem
- 6.3Isolation
- 6.3.1Concurrency control
- 6.3.1.1Two-phase locking
- Transaction schedule
- Deadlocks
- 6.3.1.2Multi-Version Concurrency Control
- Oracle
- SQL Server
- PostgreSQL
- MySQL
- 6.3.2Phenomena
- 6.3.2.1Dirty write
- 6.3.2.2Dirty read
- 6.3.2.3Non-repeatable read
- 6.3.2.4Phantom read
- 6.3.2.5Read skew
- 6.3.2.6Write skew
- 6.3.2.7Lost update
- 6.3.3Isolation levels
- 6.3.3.1Read Uncommitted
- Oracle
- SQL Server
- PostgreSQL
- MySQL
- 6.3.3.2Read Committed
- Oracle
- PostgreSQL
- MySQL
- SQL Server
- 6.3.3.3Repeatable Read
- Oracle
- SQL Server
- PostgreSQL
- MySQL
- 6.3.3.4Serializable
- Oracle
- SQL Server
- PostgreSQL
- MySQL
- 6.4Durability
- What about undo logs?
- Oracle
- SQL Server
- PostgreSQL
- MySQL
- 6.5Read-only transactions
- Oracle
- SQL Server
- PostgreSQL
- MySQL
- 6.5.1Read-only transaction routing
- Oracle
- SQL Server
- PostgreSQL
- MySQL
- 6.6Transaction boundaries
- Java EE and JTA
- 6.6.1Distributed transactions
- 6.6.1.1Two-phase commit
- The one-phase commit (1PC) optimization
- 6.6.2Declarative transactions
- Propagation
- Declarative exception handling
- Declarative read-only transactions
- Declarative isolation levels
- 6.7Application-level transactions
- 6.7.1Pessimistic and optimistic locking
- 6.7.1.1Pessimistic locking
- 6.7.1.2Optimistic locking
- IIJPA and Hibernate
7.Why JPA and Hibernate matter
- Java Persistence history
- 7.1The impedance mismatch
- 7.2JPA vs. Hibernate
- Portability concerns
- 7.3Schema ownership
- The distributed commit log
- 7.4Entity state transitions
- 7.5Write-based optimizations
- SQL injection prevention
- Auto-generated DML statements
- Write-behind cache
- Transparent statement batching
- Application-level concurrency control
- 7.6Read-based optimizations
- The fetching responsibility
- Prefer projections for read-only views
- The second-level cache
- 7.7Wrap-up
8.Connection Management and Monitoring
- 8.1JPA connection management
- 8.2Hibernate connection providers
- 8.2.1DriverManagerConnectionProvider
- 8.2.2C3P0ConnectionProvider
- 8.2.3HikariCPConnectionProvider
- 8.2.4DatasourceConnectionProvider
- 8.2.5Connection release modes
- 8.3Monitoring connections
- 8.3.1Hibernate statistics
- Dropwizard Metrics
- 8.3.1.1Customizing statistics
- 8.4Statement logging
- 8.4.1Statement formatting
- 8.4.2Statement-level comments
- 8.4.3Logging parameters
- 8.4.3.1DataSource-proxy
- 8.4.3.2P6Spy
9.Mapping Types and Identifiers
- 9.1Types
- 9.1.1Primitive types
- 9.1.2String types
- 9.1.3Date and Time types
- 9.1.4Numeric types
- 9.1.5Binary types
- 9.1.6UUID types
- 9.1.7Other types
- 9.1.8Custom types
- GiST operators
- 9.2Identifiers
- Index memory impact
- 9.2.1UUID identifiers
- Oracle
- SQL Server
- PostgreSQL
- MySQL
- 9.2.1.1The assigned generator
- 9.2.2The legacy UUID generator
- 9.2.2.1The newer UUID generator
- 9.2.3Numerical identifiers
- 9.2.3.1Identity generator
- Batch updates
- 9.2.3.2Sequence generator
- 9.2.3.3Table generator
- Escaping transactional row-level locking
- 9.2.3.4Optimizers
- 9.2.3.4.1The hi/lo algorithm
- 9.2.3.4.2The default sequence identifier generator
- 9.2.3.4.3The default table identifier generator
- 9.2.3.4.4The pooled optimizer
- 9.2.3.4.5The pooled-lo optimizer
- 9.2.3.5Optimizer gain
- 9.2.3.5.1Sequence generator performance gain
- 9.2.3.5.2Table generator performance gain
- 9.2.3.6Identifier generator performance
10.Relationships
- 10.1Relationship types
- Mapping collections
- 10.2@ManyToOne
- 10.3@OneToMany
- 10.3.1Bidirectional @OneToMany
- Equality-based entity removal
- Identifier-based equality
- 10.3.2Unidirectional @OneToMany
- 10.3.3Ordered unidirectional @OneToMany
- 10.3.4@OneToMany with @JoinColumn
- Bidirectional
@OneToManywith@JoinColumnrelationship - 10.3.5Unidirectional @OneToMany Set
- 10.4@ElementCollection
- 10.4.1@ElementCollection List
- 10.4.2@ElementCollection Set
- 10.5@OneToOne
- 10.5.1Unidirectional @OneToOne
- The shared primary key efficiency
- 10.5.2Bidirectional @OneToOne
- Limitations
- 10.6@ManyToMany
- 10.6.1Unidirectional @ManyToMany List
- Cascading
- 10.6.2Unidirectional @ManyToMany Set
- 10.6.3Bidirectional @ManyToMany
- 10.6.4The @OneToMany alternative
- 10.7Hypersistence Optimizer
- 10.7.1Testimonials
11.Inheritance
- 11.1Single table
- Performance and data integrity considerations
- 11.1.1Data integrity constraints
- 11.2Join table
- Performance considerations
- 11.3Table-per-class
- Performance considerations
- 11.4Mapped superclass
- Performance considerations
- Inheritance best practices
12.Flushing
- 12.1Flush modes
- FlushMode.AUTO SQL query consistency
- 12.2Events and the action queue
- 12.2.1Flush operation order
- 12.3Dirty Checking
- 12.3.1The default dirty checking mechanism
- 12.3.1.1Controlling the Persistence Context size
- 12.3.2Bytecode enhancement
13.Batching
- Session-level JDBC batching
- 13.1Batching insert statements
- Identity columns and JDBC batching
- 13.2Batching update statements
- Batching versioned data
- 13.3Batching delete statements
14.Fetching
- 14.1DTO projection
- 14.1.1DTO projection pagination
- ORDER BY
- 14.1.2Native query DTO projection
- Stored procedures
- 14.2Query fetch size
- 14.3Fetching entities
- 14.3.1Direct fetching
- 14.3.1.1Fetching a Proxy reference
- Populating a child-side parent association
- 14.3.1.2Natural identifier fetching
- Caching
- 14.3.2Query fetching
- Metamodel API
- 14.3.3Fetching associations
- Entity graphs
- 14.3.3.1FetchType.EAGER
- 14.3.3.2FetchType.LAZY
- 14.3.3.2.1The N+1 query problem
- 14.3.3.2.2How to catch N+1 query problems during testing
- 14.3.3.2.3LazyInitializationException
- 14.3.3.2.4The Open Session in View Anti-Pattern
- 14.3.3.2.5Temporary Session Lazy Loading Anti-Pattern
- 14.3.3.3Associations and pagination
- Entity queries vs DTO projections
- 14.3.4Attribute lazy fetching
- 14.3.5Fetching subentities
- 14.4Entity reference deduplication
- 14.5Query plan cache
15.Caching
- 15.1Caching flavors
- 15.2Cache synchronization strategies
- 15.2.1Cache-aside
- 15.2.2Read-through
- 15.2.3Write-invalidate
- 15.2.4Write-through
- 15.2.5Write-behind
- 15.3Database caching
- Oracle
- SQL Server
- PostgreSQL
- MySQL
- Essential, but not sufficient
- 15.4Application-level caching
- 15.4.1Entity aggregates
- 15.4.2Distributed key-value stores
- 15.4.3Cache synchronization patterns
- 15.4.4Synchronous updates
- 15.4.5Asynchronous updates
- 15.4.5.1Change data capture
- Oracle
- SQL Server
- PostgreSQL
- MySQL
- Denormalization ripple effect
- 15.5Second-level caching
- 15.5.1Enabling the second-level cache
- 15.5.2Entity cache loading flow
- 15.5.3Entity cache entry
- Hydrated and disassembled state
- 15.5.3.1Entity reference cache store
- 15.5.4Collection cache entry
- 15.5.5Query cache entry
- 15.5.6Cache concurrency strategies
- 15.5.6.1READ_ONLY
- 15.5.6.1.1Inserting READ_ONLY cache entries
- 15.5.6.1.2Updating READ_ONLY cache entries
- 15.5.6.1.3Deleting READ_ONLY cache entries
- 15.5.6.2NONSTRICT_READ_WRITE
- 15.5.6.2.1Inserting NONSTRICT_READ_WRITE cache entries
- 15.5.6.2.2Updating NONSTRICT_READ_WRITE cache entries
- 15.5.6.2.3Risk of inconsistencies
- 15.5.6.2.4Deleting NONSTRICT_READ_WRITE cache entries
- 15.5.6.3READ_WRITE
- 15.5.6.3.1Inserting READ_WRITE cache entries
- 15.5.6.3.2Updating READ_WRITE cache entries
- 15.5.6.3.3Deleting READ_WRITE cache entries
- 15.5.6.3.4Soft locking concurrency control
- 15.5.6.4TRANSACTIONAL
- 15.5.6.4.1XA_Strict mode
- 15.5.6.4.2XA mode
- 15.5.6.4.3Inserting TRANSACTIONAL cache entries
- 15.5.6.4.4Updating TRANSACTIONAL cache entries
- 15.5.6.4.5Deleting TRANSACTIONAL cache entries
- Choosing the right cache concurrency strategy
- 15.5.7Query cache strategy
- 15.5.7.1Tablespace query cache invalidation
- 15.5.7.2Native SQL statement query cache invalidation
- Query cache applicability
16.Concurrency Control
- 16.1Hibernate optimistic locking
- 16.1.1The implicit optimistic locking mechanism
- Logical vs. Physical clocks
- 16.1.1.1Resolving optimistic locking conflicts
- 16.1.1.2Splitting entities
- 16.1.1.3Versionless optimistic locking
- 16.1.1.3.1OptimisticLockType.DIRTY update caveat
- Statefulness to the rescue
- 16.2The explicit locking mechanism
- 16.2.1PESSIMISTIC_READ and PESSIMISTIC_WRITE
- Oracle
- SQL Server
- PostgreSQL
- MySQL
- 16.2.1.1Lock scope
- 16.2.1.2Lock timeout
- Follow-on locking
- LockMode.UPGRADE_SKIPLOCKED
- Hibernate 5.2.1 follow-on locking improvements
- 16.2.2LockModeType.OPTIMISTIC
- 16.2.2.1Inconsistency risk
- 16.2.3LockModeType.OPTIMISTIC_FORCE_INCREMENT
- 16.2.4LockModeType.PESSIMISTIC_FORCE_INCREMENT
- IIIJOOQ
17.Why jOOQ matters
- 17.1How jOOQ works
- 17.2DML statements
- 17.3Java-based schema
- 17.4Upsert
- 17.4.1Oracle
- 17.4.2SQL Server
- 17.4.3PostgreSQL
- 17.4.4MySQL
- 17.5Batch updates
- 17.6Inlining bind parameters
- Previous Hibernate and jOOQ SQL snippet format
- 17.7Complex queries
- 17.8Stored procedures and functions
- 17.9Streaming
- 17.10Keyset pagination
Get the free sample chapters
Click the buttons to get the free sample in PDF or EPUB, or read the sample online here
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.
Now, this is technically risky for us, since you'll have the book or course files either way. But we're so confident in our products and services, and in our authors and readers, that we're happy to offer a full money back guarantee for everything we sell.
You can only find out how good something is by trying it, and because of our 100% money back guarantee there's literally no risk to do so!
So, there's no reason not to click the Add to Cart button, is there?
See full terms...
Earn $8 on a $10 Purchase, and $16 on a $20 Purchase
We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book 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 $14 million writing, publishing and selling on Leanpub.
Learn more about writing 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.
Learn more about Leanpub's ebook formats and where to read them
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.