High-Performance Java Persistence – Chapter 9 – Hibernate Connection Management
Imagine having a tool that can automatically detect JPA and Hibernate performance issues. Hypersistence Optimizer is that tool!
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 18.104.22.168 Customizing statistics 9.4 Statement logging 9.4.1 Statement formatting 9.4.2 Statement-level comments 9.4.3 Logging parameters 22.214.171.124 DataSource-proxy 126.96.36.199 P6Spy
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.