High-Performance Java Persistence – Part Two

Another milestone has been reached

The second part of High-Performance Java Persistence book is out. It’s been almost a year since I started writing this book, and seven months since I published the first part.

Table of content

Before explaining what the second part is all about, it’s better to take a look at the current table of content:

I Introduction
1. Preface
1.1 The database server and the connectivity layer
1.1.1 The ORM framework
1.1.2 The native query builder framework
2. Performance and Scaling
2.1 Response time and throughput
2.2 Database connections boundaries
2.3 Scaling up and scaling out
2.3.1 Master-Slave replication
2.3.2 Multi-Master replication
2.3.3 Sharding
II JDBC and Database Essentials
3. JDBC Connection Management
3.1 DriverManager
3.2 DataSource
3.2.1 Why is pooling so much faster?
3.3 Queuing theory capacity planning
3.4 Practical database connection provisioning
3.4.1 A real-life connection pool monitoring example Concurrent connection request count metric Concurrent connection count metric Maximum pool size metric Connection acquisition time metric Retry attempts metric Overall connection acquisition time metric Connection lease time metric
4. Batch Updates
4.1 Batching Statements
4.2 Batching PreparedStatements
4.2.1 Choosing the right batch size
4.2.2 Bulk operations
4.3 Retrieving auto-generated keys
4.3.1 Sequences to the rescue
5. Statement Caching
5.1 Statement lifecycle
5.1.1 Parser
5.1.2 Optimizer Execution plan visualization
5.1.3 Executor
5.2 Caching performance gain
5.3 Server-side statement caching
5.3.1 Bind-sensitive execution plans
5.4 Client-side statement caching
6. ResultSet Fetching
6.1 ResultSet scrollability
6.2 ResultSet changeability
6.3 ResultSet holdability
6.4 Fetching size
6.5 ResultSet size
6.5.1 Too many rows SQL limit clause JDBC max rows Less is more
6.5.2 Too many columns
7. Transactions
7.1 Atomicity
7.2 Consistency
7.3 Isolation
7.3.1 Concurrency control Two-phase locking Multi-Version Concurrency Control
7.3.2 Phenomena Dirty write Dirty read Non-repeatable read Phantom read Read skew Write skew Lost update
7.3.3 Isolation levels Read Uncommitted Read Committed Repeatable Read Serializable
7.4 Durability
7.5 Read-only transactions
7.5.1 Read-only transaction routing
7.6 Transaction boundaries
7.6.1 Distributed transactions Two-phase commit
7.6.2 Declarative transactions
7.7 Application-level transactions
7.7.1 Pessimistic and optimistic locking Pessimistic locking Optimistic locking
III JPA and Hibernate
8. Why JPA and Hibernate matter
8.1 The impedance mismatch
8.2 JPA vs. Hibernate
8.3 Schema ownership
8.4 Write-based optimizations
8.5 Read-based optimizations
8.6 Wrap-up
9. Connection Management and Monitoring
9.1 JPA connection management
9.2 Hibernate connection providers
9.2.1 DriverManagerConnectionProvider
9.2.2 C3P0ConnectionProvider
9.2.3 HikariCPConnectionProvider
9.2.4 DatasourceConnectionProvider
9.2.5 Connection release modes
9.3 Monitoring connections
9.3.1 Hibernate statistics Customizing statistics
9.4 Statement logging
9.4.1 Statement formatting
9.4.2 Statement-level comments
9.4.3 Logging parameters DataSource-proxy P6Spy
10. Mapping Types and Identifiers
10.1 Types
10.1.1 Primitive types
10.1.2 String types
10.1.3 Date and Time types
10.1.4 Numeric types
10.1.5 Binary types
10.1.6 UUID types
10.1.7 Other types
10.1.8 Custom types
10.2 Identifiers
10.2.1 UUID identifiers The assigned generator
10.2.2 The legacy UUID generator The newer UUID generator
10.2.3 Numerical identifiers Identity generator Sequence generator Table generator Optimizers The hi/lo algorithm The default sequence identifier generator The default table identifier generator The pooled optimizer The pooled-lo optimizer Optimizer gain Sequence generator performance gain Table generator performance gain Identifier generator performance
11. Relationships
11.1 Relationship types
11.2 @ManyToOne
11.3 @OneToMany
11.3.1 Bidirectional @OneToMany
11.3.2 Unidirectional @OneToMany
11.3.3 Ordered unidirectional @OneToMany @ElementCollection
11.3.4 @OneToMany with @JoinColumn
11.3.5 Unidirectional @OneToMany Set
11.4 @OneToOne
11.4.1 Unidirectional @OneToOne
11.4.2 Bidirectional @OneToOne
11.5 @ManyToMany
11.5.1 Unidirectional @ManyToMany
11.5.2 Bidirectional @ManyToMany
11.5.3 The @OneToMany alternative
12. Inheritance
12.1 Single table
12.2 Join table
12.3 Table-per-class
12.4 Mapped superclass
13. Flushing
13.1 Flush modes
13.2 Events and the action queue
13.2.1 Flush operation order
13.3 Dirty Checking
13.3.1 The default dirty checking mechanism Controlling the Persistence Context size
13.3.2 Bytecode enhancement
14. Batching
14.1 Batching insert statements
14.2 Batching update statements
14.3 Batching delete statements
15. Fetching
15.1 DTO projection
15.1.1 DTO projection pagination
15.1.2 Native query DTO projection
15.2 Query fetch size
15.3 Fetching entities
15.3.1 Direct fetching Fetching a Proxy reference Natural identifier fetching
15.3.2 Query fetching
15.3.3 Fetching associations FetchType.EAGER FetchType.LAZY The N+1 query problem How to catch N+1 query problems during testing LazyInitializationException The Open Session in View Anti-Pattern Temporary Session Lazy Loading Anti-Pattern Associations and pagination
15.4 Query plan cache
16. Caching
16.1 Caching flavors
16.2 Cache synchronization strategies
16.2.1 Cache-aside
16.2.2 Read-through
16.2.3 Write-invalidate
16.2.4 Write-through
16.2.5 Write-behind
16.3 Database caching
16.4 Application-level caching
16.4.1 Entity aggregates
16.4.2 Distributed key-value stores
16.4.3 Cache synchronization patterns
16.4.4 Synchronous updates
16.4.5 Asynchronous updates Change data capture
16.5 Second-level caching
16.5.1 Enabling the second-level cache
16.5.2 Entity cache loading flow
16.5.3 Entity cache entry Entity reference cache store
16.5.4 Collection cache entry
16.5.5 Query cache entry
16.5.6 Cache concurrency strategies READ_ONLY Inserting READ_ONLY cache entries Updating READ_ONLY cache entries Deleting READ_ONLY cache entries NONSTRICT_READ_WRITE Inserting NONSTRICT_READ_WRITE cache entries Updating NONSTRICT_READ_WRITE cache entries Risk of inconsistencies Deleting NONSTRICT_READ_WRITE cache entries READ_WRITE Inserting READ_WRITE cache entries Updating READ_WRITE cache entries Deleting READ_WRITE cache entries Soft locking concurrency control TRANSACTIONAL XA_Strict mode XA mode Inserting TRANSACTIONAL cache entries Updating TRANSACTIONAL cache entries Deleting TRANSACTIONAL cache entries
16.5.7 Query cache strategy Table space query invalidation Native SQL statement query invalidation
17. Concurrency Control
17.1 Hibernate optimistic locking
17.1.1 The implicit optimistic locking mechanism Resolving optimistic locking conflicts Splitting entities Versionless optimistic locking OptimisticLockType.DIRTY update caveat
17.2 The explicit locking mechanism
17.2.1 PESSIMISTIC_READ and PESSIMISTIC_WRITE Lock scope Lock timeout
17.2.2 LockModeType.OPTIMISTIC Inconsistency risk

I initially estimated that the whole book would be around 250-300 pages. I was wrong. Even without the third part, the book is over 400 pages, and it covers database essentials, JDBC drivers peculiarities, as well as many topics about JPA and Hibernate.

The first part of the book is explained in this post.

The second part has been covered by the following articles:

The 17th chapter has just been released, and it goes through all sorts of concurrency control idioms. One of the greatest advantages of using JPA and Hibernate is that it provides advanced concurrency control mechanisms. I don’t talk only about the typical numerical version optimistic locking, but also about the versionless application-level concurrency control strategy and the subentity splitting pattern.

This chapter covers pessimistic locking as well, going beyond the classic PESSIMISTIC_READ and PESSIMISTIC_WRITE which you might already be familiar with. I describe how the follow-on locking mechanism works when the database engine cannot apply the FOR UPDATE clause properly. You can also find a detailed explanation of the SKIP LOCKED clause, which, like many other features, it’s a Hibernate-specific feature.

More to come

Even with so many topics, the book is still in progress because the third part is going to cover jOOQ, so stay tuned!

If you liked this article, you might want to subscribe to my newsletter too.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s