Compare with

Comparison of Hibernate with PostgreSQL server vs OpenJPA with H2 embedded

Each of the following tables focuses on a specific database operation, where the last table presents average results comparison.

Speed comparison of JPA database persistence operations (normalized score, higher is better)

Transaction Size =>Few EntitiesMany EntitiesAverage Score
 Hibernate
PostgreSQL server
OpenJPA
H2 embedded
Hibernate
PostgreSQL server
OpenJPA
H2 embedded
Hibernate
PostgreSQL server
OpenJPA
H2 embedded
Basic Person Test7.117.13.45.85.211.5
Element Collection Test2.910.91.74.92.37.9
Inheritance Test7.014.33.65.95.310.1
Indexing Test9.324.46.113.77.719.1
Graph (Binary Tree) Test3.06.82.96.72.96.7
Multithreading Test31.734.213.910.222.822.2
All Tests10.217.95.37.97.712.9

The results above show that in general OpenJPA with H2 embedded is more efficient than Hibernate with PostgreSQL server in persisting JPA entity objects to the database.

A large performance gap has been detected when using JPA element collections with small transaction size. Comparing the normalized speed of Hibernate with PostgreSQL database server (2.9) to the normalized speed of OpenJPA with H2 embedded database (10.9) reveals that in that case, OpenJPA with H2 embedded is 3.8 times faster than Hibernate with PostgreSQL server.

Speed comparison of JPA database retrieval operations (normalized score, higher is better)

Retrieval Size =>Few EntitiesMany EntitiesAverage Score
 Hibernate
PostgreSQL server
OpenJPA
H2 embedded
Hibernate
PostgreSQL server
OpenJPA
H2 embedded
Hibernate
PostgreSQL server
OpenJPA
H2 embedded
Basic Person Test5.514.611.527.28.520.9
Element Collection Test0.0250.00460.0174.30.0212.1
Inheritance Test5.20.01114.07.49.63.7
Indexing Test4.617.013.335.08.926.0
Graph (Binary Tree) Test0.611.00.781.40.701.2
Multithreading Test11.318.717.027.614.223.1
All Tests4.58.69.417.17.012.8

The results above show that in general OpenJPA with H2 embedded is more efficient than Hibernate with PostgreSQL server in retrieving JPA entity objects from the database.

A huge performance gap has been detected when using JPA element collections with large retrieval size. Comparing the normalized speed of Hibernate with PostgreSQL database server (0.017) to the normalized speed of OpenJPA with H2 embedded database (4.3) reveals that in that case, OpenJPA with H2 embedded is 253 times faster than Hibernate with PostgreSQL server.

On the other hand, OpenJPA with H2 embedded is slower, for instance, when using class inheritance in the object model with small retrieval size. Comparing the normalized speed of OpenJPA with H2 embedded database (0.011) to the normalized speed of Hibernate with PostgreSQL database server (5.2) reveals that in that case, OpenJPA with H2 embedded is 473 times slower than Hibernate with PostgreSQL server.

Speed comparison of JPA database query operations (normalized score, higher is better)

Retrieval Size =>Few EntitiesMany EntitiesAverage Score
 Hibernate
PostgreSQL server
OpenJPA
H2 embedded
Hibernate
PostgreSQL server
OpenJPA
H2 embedded
Hibernate
PostgreSQL server
OpenJPA
H2 embedded
Basic Person Test55.55.06.11.130.83.1
Element Collection Test11.01.70.0161.35.51.5
Inheritance Test52.32.28.71.230.51.7
Indexing Test0.05013.88.823.24.418.5
Multithreading Test55.21.49.20.6032.20.99
All Tests34.84.86.65.520.75.1

The results above show that in general Hibernate with PostgreSQL server is much more efficient than OpenJPA with H2 embedded in executing the tested JPA queries. Comparing the normalized speed of OpenJPA with H2 embedded database (5.1) to the normalized speed of Hibernate with PostgreSQL database server (20.7) reveals that in these tests, Hibernate with PostgreSQL server is 4.1 times faster than OpenJPA with H2 embedded.

A huge performance gap has been detected when using multithreading with small retrieval size. Comparing the normalized speed of OpenJPA with H2 embedded database (1.4) to the normalized speed of Hibernate with PostgreSQL database server (55.2) reveals that in that case, Hibernate with PostgreSQL server is 39.4 times faster than OpenJPA with H2 embedded.

On the other hand, Hibernate with PostgreSQL server is slower, for instance, when using database indexes with small retrieval size. Comparing the normalized speed of Hibernate with PostgreSQL database server (0.050) to the normalized speed of OpenJPA with H2 embedded database (13.8) reveals that in that case, Hibernate with PostgreSQL server is 276 times slower than OpenJPA with H2 embedded.

Speed comparison of JPA database update operations (normalized score, higher is better)

Transaction Size =>Few EntitiesMany EntitiesAverage Score
 Hibernate
PostgreSQL server
OpenJPA
H2 embedded
Hibernate
PostgreSQL server
OpenJPA
H2 embedded
Hibernate
PostgreSQL server
OpenJPA
H2 embedded
Basic Person Test5.310.02.76.04.08.0
Element Collection Test0.0670.0110.0263.80.0461.9
Inheritance Test5.40.0463.85.04.62.5
Indexing Test5.48.94.37.04.88.0
Graph (Binary Tree) Test1.12.40.581.30.821.9
Multithreading Test29.616.66.34.318.010.4
All Tests7.86.32.94.65.45.4

The results above show that in general OpenJPA with H2 embedded is equivalent to Hibernate with PostgreSQL server in updating JPA entity objects in the database.

A huge performance gap has been detected when using JPA element collections with large transaction size. Comparing the normalized speed of Hibernate with PostgreSQL database server (0.026) to the normalized speed of OpenJPA with H2 embedded database (3.8) reveals that in that case, OpenJPA with H2 embedded is 146 times faster than Hibernate with PostgreSQL server.

On the other hand, OpenJPA with H2 embedded is slower, for instance, when using class inheritance in the object model with small transaction size. Comparing the normalized speed of OpenJPA with H2 embedded database (0.046) to the normalized speed of Hibernate with PostgreSQL database server (5.4) reveals that in that case, OpenJPA with H2 embedded is 117 times slower than Hibernate with PostgreSQL server.

Speed comparison of JPA database removal operations (normalized score, higher is better)

Transaction Size =>Few EntitiesMany EntitiesAverage Score
 Hibernate
PostgreSQL server
OpenJPA
H2 embedded
Hibernate
PostgreSQL server
OpenJPA
H2 embedded
Hibernate
PostgreSQL server
OpenJPA
H2 embedded
Basic Person Test5.318.34.211.14.814.7
Element Collection Test0.0200.012stopped2.90.00981.4
Inheritance Test5.10.0304.26.64.63.3
Indexing Test9.523.26.39.77.916.4
Graph (Binary Tree) Test0.0121.80.0122.40.0122.1
Multithreading Test23.331.221.817.322.524.2
All Tests7.212.46.18.36.610.4

The results above show that in general OpenJPA with H2 embedded is more efficient than Hibernate with PostgreSQL server in deleting JPA entity objects from the database.

A huge performance gap has been detected when using graphs of objects with large transaction size. Comparing the normalized speed of Hibernate with PostgreSQL database server (0.012) to the normalized speed of OpenJPA with H2 embedded database (2.4) reveals that in that case, OpenJPA with H2 embedded is 200 times faster than Hibernate with PostgreSQL server.

On the other hand, OpenJPA with H2 embedded is slower, for instance, when using class inheritance in the object model with small transaction size. Comparing the normalized speed of OpenJPA with H2 embedded database (0.030) to the normalized speed of Hibernate with PostgreSQL database server (5.1) reveals that in that case, OpenJPA with H2 embedded is 170 times slower than Hibernate with PostgreSQL server.

Comparison of JPA/Database speed - the averages (normalized score, higher is better)

Transaction/Retrieval SizeFew EntitiesMany EntitiesAverage Score
 Hibernate
PostgreSQL server
OpenJPA
H2 embedded
Hibernate
PostgreSQL server
OpenJPA
H2 embedded
Hibernate
PostgreSQL server
OpenJPA
H2 embedded
Basic Person Test15.713.05.610.210.711.6
Element Collection Test2.82.50.353.41.63.0
Inheritance Test15.03.36.95.210.94.3
Indexing Test5.817.57.817.76.817.6
Graph (Binary Tree) Test1.23.01.13.01.13.0
Multithreading Test30.220.413.612.021.916.2
All Tests12.110.26.08.89.19.5

The results above show that in general OpenJPA with H2 embedded is slightly more efficient than Hibernate with PostgreSQL server in performing JPA database operations.

A large performance gap has been detected when using JPA element collections with large transaction/retrieval size. Comparing the normalized speed of Hibernate with PostgreSQL database server (0.35) to the normalized speed of OpenJPA with H2 embedded database (3.4) reveals that in that case, OpenJPA with H2 embedded is 9.7 times faster than Hibernate with PostgreSQL server.

On the other hand, OpenJPA with H2 embedded is slower, for instance, when using class inheritance in the object model with small transaction/retrieval size. Comparing the normalized speed of OpenJPA with H2 embedded database (3.3) to the normalized speed of Hibernate with PostgreSQL database server (15.0) reveals that in that case, OpenJPA with H2 embedded is 4.5 times slower than Hibernate with PostgreSQL server.

Other Head to Head DBMS/JPA Comparisons