Compare with

Comparison of OpenJPA with H2 embedded vs Hibernate with PostgreSQL server

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
 OpenJPA
H2 embedded
Hibernate
PostgreSQL server
OpenJPA
H2 embedded
Hibernate
PostgreSQL server
OpenJPA
H2 embedded
Hibernate
PostgreSQL server
Basic Person Test17.17.15.83.411.55.2
Element Collection Test10.92.94.91.77.92.3
Inheritance Test14.37.05.93.610.15.3
Indexing Test24.49.313.76.119.17.7
Graph (Binary Tree) Test6.83.06.72.96.72.9
Multithreading Test34.231.710.213.922.222.8
All Tests17.910.27.95.312.97.7

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
 OpenJPA
H2 embedded
Hibernate
PostgreSQL server
OpenJPA
H2 embedded
Hibernate
PostgreSQL server
OpenJPA
H2 embedded
Hibernate
PostgreSQL server
Basic Person Test14.65.527.211.520.98.5
Element Collection Test0.00460.0254.30.0172.10.021
Inheritance Test0.0115.27.414.03.79.6
Indexing Test17.04.635.013.326.08.9
Graph (Binary Tree) Test1.00.611.40.781.20.70
Multithreading Test18.711.327.617.023.114.2
All Tests8.64.517.19.412.87.0

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
 OpenJPA
H2 embedded
Hibernate
PostgreSQL server
OpenJPA
H2 embedded
Hibernate
PostgreSQL server
OpenJPA
H2 embedded
Hibernate
PostgreSQL server
Basic Person Test5.055.51.16.13.130.8
Element Collection Test1.711.01.30.0161.55.5
Inheritance Test2.252.31.28.71.730.5
Indexing Test13.80.05023.28.818.54.4
Multithreading Test1.455.20.609.20.9932.2
All Tests4.834.85.56.65.120.7

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
 OpenJPA
H2 embedded
Hibernate
PostgreSQL server
OpenJPA
H2 embedded
Hibernate
PostgreSQL server
OpenJPA
H2 embedded
Hibernate
PostgreSQL server
Basic Person Test10.05.36.02.78.04.0
Element Collection Test0.0110.0673.80.0261.90.046
Inheritance Test0.0465.45.03.82.54.6
Indexing Test8.95.47.04.38.04.8
Graph (Binary Tree) Test2.41.11.30.581.90.82
Multithreading Test16.629.64.36.310.418.0
All Tests6.37.84.62.95.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
 OpenJPA
H2 embedded
Hibernate
PostgreSQL server
OpenJPA
H2 embedded
Hibernate
PostgreSQL server
OpenJPA
H2 embedded
Hibernate
PostgreSQL server
Basic Person Test18.35.311.14.214.74.8
Element Collection Test0.0120.0202.9stopped1.40.0098
Inheritance Test0.0305.16.64.23.34.6
Indexing Test23.29.59.76.316.47.9
Graph (Binary Tree) Test1.80.0122.40.0122.10.012
Multithreading Test31.223.317.321.824.222.5
All Tests12.47.28.36.110.46.6

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
 OpenJPA
H2 embedded
Hibernate
PostgreSQL server
OpenJPA
H2 embedded
Hibernate
PostgreSQL server
OpenJPA
H2 embedded
Hibernate
PostgreSQL server
Basic Person Test13.015.710.25.611.610.7
Element Collection Test2.52.83.40.353.01.6
Inheritance Test3.315.05.26.94.310.9
Indexing Test17.55.817.77.817.66.8
Graph (Binary Tree) Test3.01.23.01.13.01.1
Multithreading Test20.430.212.013.616.221.9
All Tests10.212.18.86.09.59.1

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