Compare with

Comparison of Hibernate with H2 server 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
 Hibernate
H2 server
Hibernate
PostgreSQL server
Hibernate
H2 server
Hibernate
PostgreSQL server
Hibernate
H2 server
Hibernate
PostgreSQL server
Basic Person Test4.67.13.03.43.85.2
Element Collection Test3.72.91.11.72.42.3
Inheritance Test6.77.03.13.64.95.3
Indexing Test8.29.34.26.16.27.7
Graph (Binary Tree) Test3.43.03.92.93.72.9
Multithreading Test6.831.75.013.95.922.8
All Tests5.610.23.45.34.57.7

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

A large performance gap has been detected when using multithreading with small transaction size. Comparing the normalized speed of Hibernate with H2 database server (6.8) to the normalized speed of Hibernate with PostgreSQL database server (31.7) reveals that in that case, Hibernate with PostgreSQL server is 4.7 times faster than Hibernate with H2 server.

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

Retrieval Size =>Few EntitiesMany EntitiesAverage Score
 Hibernate
H2 server
Hibernate
PostgreSQL server
Hibernate
H2 server
Hibernate
PostgreSQL server
Hibernate
H2 server
Hibernate
PostgreSQL server
Basic Person Test3.15.56.011.54.68.5
Element Collection Test1.00.0251.10.0171.00.021
Inheritance Test2.95.27.614.05.29.6
Indexing Test2.64.67.013.34.88.9
Graph (Binary Tree) Test0.420.611.10.780.780.70
Multithreading Test6.511.310.517.08.514.2
All Tests2.84.55.69.44.27.0

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

On the other hand, Hibernate with PostgreSQL server is slower, for instance, 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 Hibernate with H2 database server (1.1) reveals that in that case, Hibernate with PostgreSQL server is 64.7 times slower than Hibernate with H2 server.

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

Retrieval Size =>Few EntitiesMany EntitiesAverage Score
 Hibernate
H2 server
Hibernate
PostgreSQL server
Hibernate
H2 server
Hibernate
PostgreSQL server
Hibernate
H2 server
Hibernate
PostgreSQL server
Basic Person Test3.755.51.06.12.330.8
Element Collection Test3.711.00.630.0162.25.5
Inheritance Test3.252.31.48.72.330.5
Indexing Test1.70.0505.88.83.84.4
Multithreading Test1.155.20.889.21.032.2
All Tests2.734.81.96.62.320.7

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

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

On the other hand, Hibernate with PostgreSQL server is slower, for instance, when using JPA element collections with large retrieval size. Comparing the normalized speed of Hibernate with PostgreSQL database server (0.016) to the normalized speed of Hibernate with H2 database server (0.63) reveals that in that case, Hibernate with PostgreSQL server is 39.4 times slower than Hibernate with H2 server.

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

Transaction Size =>Few EntitiesMany EntitiesAverage Score
 Hibernate
H2 server
Hibernate
PostgreSQL server
Hibernate
H2 server
Hibernate
PostgreSQL server
Hibernate
H2 server
Hibernate
PostgreSQL server
Basic Person Test2.95.31.82.72.44.0
Element Collection Test2.60.0671.10.0261.90.046
Inheritance Test3.25.42.53.82.94.6
Indexing Test2.95.42.74.32.84.8
Graph (Binary Tree) Test1.21.10.430.580.790.82
Multithreading Test5.629.62.46.34.018.0
All Tests3.17.81.82.92.55.4

The results above show that in general Hibernate with PostgreSQL server is more efficient than Hibernate with H2 server in updating JPA entity objects in the database. Comparing the normalized speed of Hibernate with H2 database server (2.5) to the normalized speed of Hibernate with PostgreSQL database server (5.4) reveals that in these tests, Hibernate with PostgreSQL server is 2.2 times faster than Hibernate with H2 server.

A large performance gap has been detected when using multithreading with small transaction size. Comparing the normalized speed of Hibernate with H2 database server (5.6) to the normalized speed of Hibernate with PostgreSQL database server (29.6) reveals that in that case, Hibernate with PostgreSQL server is 5.3 times faster than Hibernate with H2 server.

On the other hand, Hibernate with PostgreSQL server is slower, for instance, 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 Hibernate with H2 database server (1.1) reveals that in that case, Hibernate with PostgreSQL server is 42.3 times slower than Hibernate with H2 server.

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

Transaction Size =>Few EntitiesMany EntitiesAverage Score
 Hibernate
H2 server
Hibernate
PostgreSQL server
Hibernate
H2 server
Hibernate
PostgreSQL server
Hibernate
H2 server
Hibernate
PostgreSQL server
Basic Person Test3.85.32.44.23.14.8
Element Collection Test1.90.0201.1stopped1.50.0098
Inheritance Test3.75.12.54.23.14.6
Indexing Test7.69.53.16.35.37.9
Graph (Binary Tree) Test0.990.0120.910.0120.950.012
Multithreading Test6.123.37.321.86.722.5
All Tests4.07.22.96.13.56.6

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

A large performance gap has been detected when using multithreading with small transaction size. Comparing the normalized speed of Hibernate with H2 database server (6.1) to the normalized speed of Hibernate with PostgreSQL database server (23.3) reveals that in that case, Hibernate with PostgreSQL server is 3.8 times faster than Hibernate with H2 server.

On the other hand, Hibernate with PostgreSQL server is slower, for instance, when using JPA element collections with small transaction size. Comparing the normalized speed of Hibernate with PostgreSQL database server (0.020) to the normalized speed of Hibernate with H2 database server (1.9) reveals that in that case, Hibernate with PostgreSQL server is 95.0 times slower than Hibernate with H2 server.

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

Transaction/Retrieval SizeFew EntitiesMany EntitiesAverage Score
 Hibernate
H2 server
Hibernate
PostgreSQL server
Hibernate
H2 server
Hibernate
PostgreSQL server
Hibernate
H2 server
Hibernate
PostgreSQL server
Basic Person Test3.615.72.85.63.210.7
Element Collection Test2.62.81.00.351.81.6
Inheritance Test4.015.03.46.93.710.9
Indexing Test4.65.84.57.84.66.8
Graph (Binary Tree) Test1.51.21.61.11.61.1
Multithreading Test5.230.25.213.65.221.9
All Tests3.712.13.26.03.49.1

The results above show that in general Hibernate with PostgreSQL server is more efficient than Hibernate with H2 server in performing JPA database operations. Comparing the normalized speed of Hibernate with H2 database server (3.4) to the normalized speed of Hibernate with PostgreSQL database server (9.1) reveals that in these tests, Hibernate with PostgreSQL server is 2.7 times faster than Hibernate with H2 server.

A large performance gap has been detected when using multithreading with small transaction/retrieval size. Comparing the normalized speed of Hibernate with H2 database server (5.2) to the normalized speed of Hibernate with PostgreSQL database server (30.2) reveals that in that case, Hibernate with PostgreSQL server is 5.8 times faster than Hibernate with H2 server.

On the other hand, Hibernate with PostgreSQL server is slower, for instance, 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 Hibernate with H2 database server (1.0) reveals that in that case, Hibernate with PostgreSQL server is 2.9 times slower than Hibernate with H2 server.

Other Head to Head DBMS/JPA Comparisons