Leanpub Header

Skip to main content

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.

Minimum price

$29.95

$34.95

You pay

$34.95

Author earns

$27.96

Packages

Details
$

...Or Buy With Credits!

You can get credits monthly with a Reader Membership
PDF
EPUB
WEB
2,826
Readers
461
Pages
99,629Words
About

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.

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.95

    This 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

      1. The database server and the connectivity layer
      2. The application data access layer
      3. The ORM framework
      4. The native query builder framework
      5. About database performance benchmarks
      6. Video Course
      7. Testimonials
      8. IJDBC and Database Essentials

      1.Performance and Scaling

      1. 1.1Response time and throughput
      2. 1.2Database connections boundaries
      3. 1.3Scaling up and scaling out
      4. 1.3.1Master-Slave replication
      5. 1.3.2Multi-Master replication
      6. 1.3.3Sharding
      7. MySQL cluster auto-sharding
      8. Little’s Law

      2.JDBC Connection Management

      1. 2.1DriverManager
      2. Oracle mainframe legacy
      3. 2.2DataSource
      4. Oracle XE connection handling limitation
      5. 2.2.1Why is pooling so much faster?
      6. 2.3Queuing theory capacity planning
      7. 2.4Practical database connection provisioning
      8. 2.4.1A real-life connection pool monitoring example
      9. 2.4.1.1Concurrent connection request count metric
      10. 2.4.1.2Concurrent connection count metric
      11. 2.4.1.3Maximum pool size metric
      12. 2.4.1.4Connection acquisition time metric
      13. 2.4.1.5Retry attempts metric
      14. 2.4.1.6Overall connection acquisition time metric
      15. 2.4.1.7Connection lease time metric

      3.Batch Updates

      1. 3.1Batching Statements
      2. Oracle
      3. MySQL
      4. 3.2Batching PreparedStatements
      5. SQL injection
      6. 3.2.1Choosing the right batch size
      7. 3.2.2Bulk processing
      8. Long-running transaction caveats
      9. 3.3Retrieving auto-generated keys
      10. Oracle
      11. SQL Server
      12. PostgreSQL
      13. MySQL
      14. Oracle auto-generated key retrieval gotcha
      15. 3.3.1Sequences to the rescue
      16. Oracle
      17. SQL Server
      18. PostgreSQL
      19. Optimizing sequence calls

      4.Statement Caching

      1. 4.1Statement lifecycle
      2. 4.1.1Parser
      3. 4.1.2Optimizer
      4. 4.1.2.1Execution plan visualization
      5. Oracle
      6. PostgreSQL
      7. SQL Server
      8. MySQL
      9. MySQL
      10. 4.1.3Executor
      11. 4.2Caching performance gain
      12. 4.3Server-side statement caching
      13. Forced Parameterization
      14. Oracle
      15. SQL Server
      16. 4.3.1Bind-sensitive execution plans
      17. Oracle
      18. Bind peeking
      19. SQL Server
      20. PostgreSQL
      21. MySQL
      22. 4.4Client-side statement caching
      23. Oracle implicit statement caching
      24. Oracle explicit statement caching
      25. SQL Server
      26. PostgreSQL
      27. MySQL

      5.ResultSet Fetching

      1. 5.1ResultSet scrollability
      2. Oracle
      3. SQL Server
      4. PostgreSQL
      5. MySQL
      6. 5.2ResultSet changeability
      7. 5.3ResultSet holdability
      8. Oracle
      9. SQL Server
      10. PostgreSQL
      11. MySQL
      12. 5.4Fetching size
      13. Oracle
      14. SQL Server
      15. PostgreSQL
      16. MySQL
      17. 5.5ResultSet size
      18. 5.5.1Too many rows
      19. 5.5.1.1SQL limit clause
      20. SQL:2008
      21. Oracle
      22. SQL Server
      23. PostgreSQL and MySQL
      24. 5.5.1.2JDBC max rows
      25. Oracle
      26. SQL Server
      27. PostgreSQL
      28. MySQL
      29. 5.5.1.3Less is more
      30. 5.5.2Too many columns

      6.Transactions

      1. 6.1Atomicity
      2. Write-write conflicts
      3. Oracle
      4. SQL Server
      5. PostgreSQL
      6. MySQL
      7. 6.2Consistency
      8. MySQL
      9. Consistency as in CAP Theorem
      10. 6.3Isolation
      11. 6.3.1Concurrency control
      12. 6.3.1.1Two-phase locking
      13. Transaction schedule
      14. Deadlocks
      15. 6.3.1.2Multi-Version Concurrency Control
      16. Oracle
      17. SQL Server
      18. PostgreSQL
      19. MySQL
      20. 6.3.2Phenomena
      21. 6.3.2.1Dirty write
      22. 6.3.2.2Dirty read
      23. 6.3.2.3Non-repeatable read
      24. 6.3.2.4Phantom read
      25. 6.3.2.5Read skew
      26. 6.3.2.6Write skew
      27. 6.3.2.7Lost update
      28. 6.3.3Isolation levels
      29. 6.3.3.1Read Uncommitted
      30. Oracle
      31. SQL Server
      32. PostgreSQL
      33. MySQL
      34. 6.3.3.2Read Committed
      35. Oracle
      36. PostgreSQL
      37. MySQL
      38. SQL Server
      39. 6.3.3.3Repeatable Read
      40. Oracle
      41. SQL Server
      42. PostgreSQL
      43. MySQL
      44. 6.3.3.4Serializable
      45. Oracle
      46. SQL Server
      47. PostgreSQL
      48. MySQL
      49. 6.4Durability
      50. What about undo logs?
      51. Oracle
      52. SQL Server
      53. PostgreSQL
      54. MySQL
      55. 6.5Read-only transactions
      56. Oracle
      57. SQL Server
      58. PostgreSQL
      59. MySQL
      60. 6.5.1Read-only transaction routing
      61. Oracle
      62. SQL Server
      63. PostgreSQL
      64. MySQL
      65. 6.6Transaction boundaries
      66. Java EE and JTA
      67. 6.6.1Distributed transactions
      68. 6.6.1.1Two-phase commit
      69. The one-phase commit (1PC) optimization
      70. 6.6.2Declarative transactions
      71. Propagation
      72. Declarative exception handling
      73. Declarative read-only transactions
      74. Declarative isolation levels
      75. 6.7Application-level transactions
      76. 6.7.1Pessimistic and optimistic locking
      77. 6.7.1.1Pessimistic locking
      78. 6.7.1.2Optimistic locking
      79. IIJPA and Hibernate

      7.Why JPA and Hibernate matter

      1. Java Persistence history
      2. 7.1The impedance mismatch
      3. 7.2JPA vs. Hibernate
      4. Portability concerns
      5. 7.3Schema ownership
      6. The distributed commit log
      7. 7.4Entity state transitions
      8. 7.5Write-based optimizations
      9. SQL injection prevention
      10. Auto-generated DML statements
      11. Write-behind cache
      12. Transparent statement batching
      13. Application-level concurrency control
      14. 7.6Read-based optimizations
      15. The fetching responsibility
      16. Prefer projections for read-only views
      17. The second-level cache
      18. 7.7Wrap-up

      8.Connection Management and Monitoring

      1. 8.1JPA connection management
      2. 8.2Hibernate connection providers
      3. 8.2.1DriverManagerConnectionProvider
      4. 8.2.2C3P0ConnectionProvider
      5. 8.2.3HikariCPConnectionProvider
      6. 8.2.4DatasourceConnectionProvider
      7. 8.2.5Connection release modes
      8. 8.3Monitoring connections
      9. 8.3.1Hibernate statistics
      10. Dropwizard Metrics
      11. 8.3.1.1Customizing statistics
      12. 8.4Statement logging
      13. 8.4.1Statement formatting
      14. 8.4.2Statement-level comments
      15. 8.4.3Logging parameters
      16. 8.4.3.1DataSource-proxy
      17. 8.4.3.2P6Spy

      9.Mapping Types and Identifiers

      1. 9.1Types
      2. 9.1.1Primitive types
      3. 9.1.2String types
      4. 9.1.3Date and Time types
      5. 9.1.4Numeric types
      6. 9.1.5Binary types
      7. 9.1.6UUID types
      8. 9.1.7Other types
      9. 9.1.8Custom types
      10. GiST operators
      11. 9.2Identifiers
      12. Index memory impact
      13. 9.2.1UUID identifiers
      14. Oracle
      15. SQL Server
      16. PostgreSQL
      17. MySQL
      18. 9.2.1.1The assigned generator
      19. 9.2.2The legacy UUID generator
      20. 9.2.2.1The newer UUID generator
      21. 9.2.3Numerical identifiers
      22. 9.2.3.1Identity generator
      23. Batch updates
      24. 9.2.3.2Sequence generator
      25. 9.2.3.3Table generator
      26. Escaping transactional row-level locking
      27. 9.2.3.4Optimizers
      28. 9.2.3.4.1The hi/lo algorithm
      29. 9.2.3.4.2The default sequence identifier generator
      30. 9.2.3.4.3The default table identifier generator
      31. 9.2.3.4.4The pooled optimizer
      32. 9.2.3.4.5The pooled-lo optimizer
      33. 9.2.3.5Optimizer gain
      34. 9.2.3.5.1Sequence generator performance gain
      35. 9.2.3.5.2Table generator performance gain
      36. 9.2.3.6Identifier generator performance

      10.Relationships

      1. 10.1Relationship types
      2. Mapping collections
      3. 10.2@ManyToOne
      4. 10.3@OneToMany
      5. 10.3.1Bidirectional @OneToMany
      6. Equality-based entity removal
      7. Identifier-based equality
      8. 10.3.2Unidirectional @OneToMany
      9. 10.3.3Ordered unidirectional @OneToMany
      10. 10.3.4@OneToMany with @JoinColumn
      11. Bidirectional @OneToMany with @JoinColumn relationship
      12. 10.3.5Unidirectional @OneToMany Set
      13. 10.4@ElementCollection
      14. 10.4.1@ElementCollection List
      15. 10.4.2@ElementCollection Set
      16. 10.5@OneToOne
      17. 10.5.1Unidirectional @OneToOne
      18. The shared primary key efficiency
      19. 10.5.2Bidirectional @OneToOne
      20. Limitations
      21. 10.6@ManyToMany
      22. 10.6.1Unidirectional @ManyToMany List
      23. Cascading
      24. 10.6.2Unidirectional @ManyToMany Set
      25. 10.6.3Bidirectional @ManyToMany
      26. 10.6.4The @OneToMany alternative
      27. 10.7Hypersistence Optimizer
      28. 10.7.1Testimonials

      11.Inheritance

      1. 11.1Single table
      2. Performance and data integrity considerations
      3. 11.1.1Data integrity constraints
      4. 11.2Join table
      5. Performance considerations
      6. 11.3Table-per-class
      7. Performance considerations
      8. 11.4Mapped superclass
      9. Performance considerations
      10. Inheritance best practices

      12.Flushing

      1. 12.1Flush modes
      2. FlushMode.AUTO SQL query consistency
      3. 12.2Events and the action queue
      4. 12.2.1Flush operation order
      5. 12.3Dirty Checking
      6. 12.3.1The default dirty checking mechanism
      7. 12.3.1.1Controlling the Persistence Context size
      8. 12.3.2Bytecode enhancement

      13.Batching

      1. Session-level JDBC batching
      2. 13.1Batching insert statements
      3. Identity columns and JDBC batching
      4. 13.2Batching update statements
      5. Batching versioned data
      6. 13.3Batching delete statements

      14.Fetching

      1. 14.1DTO projection
      2. 14.1.1DTO projection pagination
      3. ORDER BY
      4. 14.1.2Native query DTO projection
      5. Stored procedures
      6. 14.2Query fetch size
      7. 14.3Fetching entities
      8. 14.3.1Direct fetching
      9. 14.3.1.1Fetching a Proxy reference
      10. Populating a child-side parent association
      11. 14.3.1.2Natural identifier fetching
      12. Caching
      13. 14.3.2Query fetching
      14. Metamodel API
      15. 14.3.3Fetching associations
      16. Entity graphs
      17. 14.3.3.1FetchType.EAGER
      18. 14.3.3.2FetchType.LAZY
      19. 14.3.3.2.1The N+1 query problem
      20. 14.3.3.2.2How to catch N+1 query problems during testing
      21. 14.3.3.2.3LazyInitializationException
      22. 14.3.3.2.4The Open Session in View Anti-Pattern
      23. 14.3.3.2.5Temporary Session Lazy Loading Anti-Pattern
      24. 14.3.3.3Associations and pagination
      25. Entity queries vs DTO projections
      26. 14.3.4Attribute lazy fetching
      27. 14.3.5Fetching subentities
      28. 14.4Entity reference deduplication
      29. 14.5Query plan cache

      15.Caching

      1. 15.1Caching flavors
      2. 15.2Cache synchronization strategies
      3. 15.2.1Cache-aside
      4. 15.2.2Read-through
      5. 15.2.3Write-invalidate
      6. 15.2.4Write-through
      7. 15.2.5Write-behind
      8. 15.3Database caching
      9. Oracle
      10. SQL Server
      11. PostgreSQL
      12. MySQL
      13. Essential, but not sufficient
      14. 15.4Application-level caching
      15. 15.4.1Entity aggregates
      16. 15.4.2Distributed key-value stores
      17. 15.4.3Cache synchronization patterns
      18. 15.4.4Synchronous updates
      19. 15.4.5Asynchronous updates
      20. 15.4.5.1Change data capture
      21. Oracle
      22. SQL Server
      23. PostgreSQL
      24. MySQL
      25. Denormalization ripple effect
      26. 15.5Second-level caching
      27. 15.5.1Enabling the second-level cache
      28. 15.5.2Entity cache loading flow
      29. 15.5.3Entity cache entry
      30. Hydrated and disassembled state
      31. 15.5.3.1Entity reference cache store
      32. 15.5.4Collection cache entry
      33. 15.5.5Query cache entry
      34. 15.5.6Cache concurrency strategies
      35. 15.5.6.1READ_ONLY
      36. 15.5.6.1.1Inserting READ_ONLY cache entries
      37. 15.5.6.1.2Updating READ_ONLY cache entries
      38. 15.5.6.1.3Deleting READ_ONLY cache entries
      39. 15.5.6.2NONSTRICT_READ_WRITE
      40. 15.5.6.2.1Inserting NONSTRICT_READ_WRITE cache entries
      41. 15.5.6.2.2Updating NONSTRICT_READ_WRITE cache entries
      42. 15.5.6.2.3Risk of inconsistencies
      43. 15.5.6.2.4Deleting NONSTRICT_READ_WRITE cache entries
      44. 15.5.6.3READ_WRITE
      45. 15.5.6.3.1Inserting READ_WRITE cache entries
      46. 15.5.6.3.2Updating READ_WRITE cache entries
      47. 15.5.6.3.3Deleting READ_WRITE cache entries
      48. 15.5.6.3.4Soft locking concurrency control
      49. 15.5.6.4TRANSACTIONAL
      50. 15.5.6.4.1XA_Strict mode
      51. 15.5.6.4.2XA mode
      52. 15.5.6.4.3Inserting TRANSACTIONAL cache entries
      53. 15.5.6.4.4Updating TRANSACTIONAL cache entries
      54. 15.5.6.4.5Deleting TRANSACTIONAL cache entries
      55. Choosing the right cache concurrency strategy
      56. 15.5.7Query cache strategy
      57. 15.5.7.1Tablespace query cache invalidation
      58. 15.5.7.2Native SQL statement query cache invalidation
      59. Query cache applicability

      16.Concurrency Control

      1. 16.1Hibernate optimistic locking
      2. 16.1.1The implicit optimistic locking mechanism
      3. Logical vs. Physical clocks
      4. 16.1.1.1Resolving optimistic locking conflicts
      5. 16.1.1.2Splitting entities
      6. 16.1.1.3Versionless optimistic locking
      7. 16.1.1.3.1OptimisticLockType.DIRTY update caveat
      8. Statefulness to the rescue
      9. 16.2The explicit locking mechanism
      10. 16.2.1PESSIMISTIC_READ and PESSIMISTIC_WRITE
      11. Oracle
      12. SQL Server
      13. PostgreSQL
      14. MySQL
      15. 16.2.1.1Lock scope
      16. 16.2.1.2Lock timeout
      17. Follow-on locking
      18. LockMode.UPGRADE_SKIPLOCKED
      19. Hibernate 5.2.1 follow-on locking improvements
      20. 16.2.2LockModeType.OPTIMISTIC
      21. 16.2.2.1Inconsistency risk
      22. 16.2.3LockModeType.OPTIMISTIC_FORCE_INCREMENT
      23. 16.2.4LockModeType.PESSIMISTIC_FORCE_INCREMENT
      24. IIIJOOQ

      17.Why jOOQ matters

      1. 17.1How jOOQ works
      2. 17.2DML statements
      3. 17.3Java-based schema
      4. 17.4Upsert
      5. 17.4.1Oracle
      6. 17.4.2SQL Server
      7. 17.4.3PostgreSQL
      8. 17.4.4MySQL
      9. 17.5Batch updates
      10. 17.6Inlining bind parameters
      11. Previous Hibernate and jOOQ SQL snippet format
      12. 17.7Complex queries
      13. 17.8Stored procedures and functions
      14. 17.9Streaming
      15. 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.

      Learn more about writing on Leanpub