How to bootstrap Hibernate without the persistence.xml file

Why?

JPA relies heavily on the persistence.xml configuration file, and the standard API to bootstrap a JPA provider programmatically requires too much boilerplate code. While in a typical enterprise application, providing a persistence.xml file is not really an issue, this requirement doesn’t get along with unit testing, especially when tests are completely isolated and they need to validate different aspects of JPA or Hibernate.

That was an issue that I bumped into when writing test cases for the High-Performance Java Persistence book. All my tests need to be isolated, and not all of them share the same settings or entities.

In my case, using a single persistence.xml file was definitely out of the question because any change would have a rippling effect through out the whole test suite.

Continue reading “How to bootstrap Hibernate without the persistence.xml file”

Advertisements

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

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 
9.3.1.1 Customizing statistics 
9.4 Statement logging
9.4.1 Statement formatting 
9.4.2 Statement-level comments 
9.4.3 Logging parameters 
9.4.3.1 DataSource-proxy 
9.4.3.2 P6Spy

Continue reading “High-Performance Java Persistence – Chapter 9 – Hibernate Connection Management”

High-Performance Java Persistence – Chapter 8 – Why JPA and Hibernate matter

Second part, Chapter 8

Now that the first part of my book is published, it’s time to focus on the second part, which covers both JPA and Hibernate.
From now on, every new chapter is going to be released right after it’s completed, so the reader doesn’t have to wait for the whole part to be finished to get access to new chapters.

Table of content

This chapter aims to remind the reader why Hibernate has its place in high-performance data access, and the table of contents looks like this:

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

Continue reading “High-Performance Java Persistence – Chapter 8 – Why JPA and Hibernate matter”

High-Performance Java Persistence – Part One

The journey

Four months, one week and two days and 114 pages; that’s how much it took to write the first part of the High-Performance Java Persistence book.

As previously stated, the book is developed in an Agile fashion. Each part represents a milestone, which is accompanied by a release. This way, the readers can get access to the book content prior to finishing the whole book (which might take a year or so).

Continue reading “High-Performance Java Persistence – Part One”