High-Performance Java Persistence – Chapter 9 – Hibernate Connection Management

Imagine having a tool that can automatically detect JPA and Hibernate performance issues. Wouldn’t that be just awesome?

Well, Hypersistence Optimizer is that tool! And it works with Spring Boot, Spring Framework, Jakarta EE, Java EE, Quarkus, or Play Framework.

So, enjoy spending your time on the things you love rather than fixing performance issues in your production system on a Saturday night!

Part 2, Chapter 9

Every new chapter of my book is released right after it’s being completed, so the reader doesn’t have to wait for the whole part to be finished to get access to new material.

Table of content

This chapter explains how to handle connections in Hibernate and how to monitor their usage as well as the statement that gets automatically generated, and the table of contents looks like this:

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 HikariConnectionProvider 
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

Chapter summary

The connection provider has a very serious impact on the overall application performance, so this chapter goes through the most common ConnectionProvider implementations and explains which are the most suitable for a high-performance OLTP system.

Hibernate has many subtleties, and one of the least known connection-related configuration options is the JTA release mode.
In this chapter, I will explain when it’s safe to override the default after_statement release mode and how much performance does it buy you.

Monitoring connections and transactions are mandatory in any enterprise system. Hibernate comes with its own statistics collector, providing an extension point mechanism to listen to Hibernate internal events. In this chapter, I explain how you can customize the default mechanism and implement a transaction tracking statistics mechanism.

Last but not least, statement logging has its quirks as well. For this reason, I explained which configuration properties propagate to the underlying Driver or to the currently configured Logger and how to print PreparedStatement bind parameter values. This chapter was the right place to introduce two very useful JDBC proxying frameworks: datasource-proxy and P6Spy, each one offering more than just statement logging.

Transactions and Concurrency Control eBook

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.