Compare with

Comparison of Hibernate with MySQL server vs Hibernate with H2 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
MySQL server
Hibernate
H2 server
Hibernate
MySQL server
Hibernate
H2 server
Hibernate
MySQL server
Hibernate
H2 server
Basic Person Test3.64.61.63.02.63.8
Element Collection Test1.63.70.721.11.12.4
Inheritance Test3.76.71.63.12.74.9
Indexing Test5.48.22.64.24.06.2
Graph (Binary Tree) Test1.53.41.23.91.43.7
Multithreading Test7.46.82.95.05.25.9
All Tests3.95.61.83.42.84.5

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

A large performance gap has been detected when using graphs of objects with large transaction size. Comparing the normalized speed of Hibernate with MySQL database server (1.2) to the normalized speed of Hibernate with H2 database server (3.9) reveals that in that case, Hibernate with H2 server is 3.2 times faster than Hibernate with MySQL server.

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

Retrieval Size =>Few EntitiesMany EntitiesAverage Score
 Hibernate
MySQL server
Hibernate
H2 server
Hibernate
MySQL server
Hibernate
H2 server
Hibernate
MySQL server
Hibernate
H2 server
Basic Person Test3.03.111.06.07.04.6
Element Collection Test0.341.01.21.10.791.0
Inheritance Test1.32.914.57.67.95.2
Indexing Test2.52.612.87.07.64.8
Graph (Binary Tree) Test0.550.420.711.10.630.78
Multithreading Test0.236.513.810.57.08.5
All Tests1.32.89.05.65.24.2

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

On the other hand, Hibernate with MySQL server is slower, for instance, when using multithreading with small retrieval size. Comparing the normalized speed of Hibernate with MySQL database server (0.23) to the normalized speed of Hibernate with H2 database server (6.5) reveals that in that case, Hibernate with MySQL server is 28.3 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
MySQL server
Hibernate
H2 server
Hibernate
MySQL server
Hibernate
H2 server
Hibernate
MySQL server
Hibernate
H2 server
Basic Person Test10.03.72.01.06.02.3
Element Collection Test6.73.70.530.633.62.2
Inheritance Test2.83.21.61.42.22.3
Indexing Test0.441.72.05.81.23.8
Multithreading Test2.11.10.980.881.51.0
All Tests4.42.71.41.92.92.3

The results above show that in general Hibernate with MySQL server is slightly more efficient than Hibernate with H2 server in executing the tested JPA queries.

A large performance gap has been detected when using simple basic entities with small retrieval size. Comparing the normalized speed of Hibernate with H2 database server (3.7) to the normalized speed of Hibernate with MySQL database server (10.0) reveals that in that case, Hibernate with MySQL server is 2.7 times faster than Hibernate with H2 server.

On the other hand, Hibernate with MySQL server is slower, for instance, when using database indexes with small retrieval size. Comparing the normalized speed of Hibernate with MySQL database server (0.44) to the normalized speed of Hibernate with H2 database server (1.7) reveals that in that case, Hibernate with MySQL server is 3.9 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
MySQL server
Hibernate
H2 server
Hibernate
MySQL server
Hibernate
H2 server
Hibernate
MySQL server
Hibernate
H2 server
Basic Person Test0.732.91.61.81.22.4
Element Collection Test0.392.61.21.10.781.9
Inheritance Test0.613.22.12.51.42.9
Indexing Test0.812.92.62.71.72.8
Graph (Binary Tree) Test0.691.20.400.430.540.79
Multithreading Test0.635.63.02.41.84.0
All Tests0.643.11.81.81.22.5

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

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

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

Transaction Size =>Few EntitiesMany EntitiesAverage Score
 Hibernate
MySQL server
Hibernate
H2 server
Hibernate
MySQL server
Hibernate
H2 server
Hibernate
MySQL server
Hibernate
H2 server
Basic Person Test1.13.81.72.41.43.1
Element Collection Test0.211.90.531.10.371.5
Inheritance Test0.653.71.82.51.23.1
Indexing Test0.817.62.03.11.45.3
Graph (Binary Tree) Test0.550.990.620.910.580.95
Multithreading Test0.356.14.17.32.26.7
All Tests0.614.01.82.91.23.5

The results above show that in general Hibernate with H2 server is more efficient than Hibernate with MySQL server in deleting JPA entity objects from the database. Comparing the normalized speed of Hibernate with MySQL database server (1.2) to the normalized speed of Hibernate with H2 database server (3.5) reveals that in these tests, Hibernate with H2 server is 2.9 times faster than Hibernate with MySQL server.

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

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

Transaction/Retrieval SizeFew EntitiesMany EntitiesAverage Score
 Hibernate
MySQL server
Hibernate
H2 server
Hibernate
MySQL server
Hibernate
H2 server
Hibernate
MySQL server
Hibernate
H2 server
Basic Person Test3.73.63.62.83.63.2
Element Collection Test1.82.60.841.01.31.8
Inheritance Test1.84.04.33.43.13.7
Indexing Test2.04.64.44.53.24.6
Graph (Binary Tree) Test0.831.50.731.60.781.6
Multithreading Test2.15.25.05.23.65.2
All Tests2.13.73.23.22.73.4

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

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

Other Head to Head DBMS/JPA Comparisons