Compare with

Comparison of Hibernate with MySQL server vs Hibernate 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
MySQL server
Hibernate
H2 embedded
Hibernate
MySQL server
Hibernate
H2 embedded
Hibernate
MySQL server
Hibernate
H2 embedded
Basic Person Test3.618.11.69.02.613.5
Element Collection Test1.613.00.726.81.19.9
Inheritance Test3.721.01.69.42.715.2
Indexing Test5.429.92.618.44.024.1
Graph (Binary Tree) Test1.517.21.220.11.418.7
Multithreading Test7.436.92.911.55.224.2
All Tests3.922.61.812.52.817.6

The results above show that in general Hibernate with H2 embedded is much more efficient than Hibernate with MySQL server in persisting JPA entity objects to the database. Comparing the normalized speed of Hibernate with MySQL database server (2.8) to the normalized speed of Hibernate with H2 embedded database (17.6) reveals that in these tests, Hibernate with H2 embedded is 6.3 times faster than Hibernate with MySQL server.

A huge 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 embedded database (20.1) reveals that in that case, Hibernate with H2 embedded is 16.8 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 embedded
Hibernate
MySQL server
Hibernate
H2 embedded
Hibernate
MySQL server
Hibernate
H2 embedded
Basic Person Test3.016.611.013.37.015.0
Element Collection Test0.344.31.24.00.794.1
Inheritance Test1.310.414.517.57.913.9
Indexing Test2.510.812.815.27.613.0
Graph (Binary Tree) Test0.552.50.714.00.633.3
Multithreading Test0.2316.213.815.77.015.9
All Tests1.310.19.011.65.210.9

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

A huge performance gap has been detected 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 embedded database (16.2) reveals that in that case, Hibernate with H2 embedded is 70.4 times faster than Hibernate with MySQL server.

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

Retrieval Size =>Few EntitiesMany EntitiesAverage Score
 Hibernate
MySQL server
Hibernate
H2 embedded
Hibernate
MySQL server
Hibernate
H2 embedded
Hibernate
MySQL server
Hibernate
H2 embedded
Basic Person Test10.04.52.01.26.02.8
Element Collection Test6.74.40.531.43.62.9
Inheritance Test2.83.11.61.52.22.3
Indexing Test0.446.62.010.51.28.6
Multithreading Test2.11.20.980.591.50.89
All Tests4.44.01.43.02.93.5

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

A huge performance gap has been detected 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 embedded database (6.6) reveals that in that case, Hibernate with H2 embedded is 15.0 times faster than Hibernate with MySQL server.

On the other hand, Hibernate with H2 embedded is slower, for instance, when using simple basic entities with small retrieval size. Comparing the normalized speed of Hibernate with H2 embedded database (4.5) to the normalized speed of Hibernate with MySQL database server (10.0) reveals that in that case, Hibernate with H2 embedded is 2.2 times slower than Hibernate with MySQL server.

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

Transaction Size =>Few EntitiesMany EntitiesAverage Score
 Hibernate
MySQL server
Hibernate
H2 embedded
Hibernate
MySQL server
Hibernate
H2 embedded
Hibernate
MySQL server
Hibernate
H2 embedded
Basic Person Test0.7312.11.66.51.29.3
Element Collection Test0.397.41.25.30.786.3
Inheritance Test0.6110.82.18.51.49.6
Indexing Test0.8110.02.67.51.78.8
Graph (Binary Tree) Test0.694.40.402.30.543.4
Multithreading Test0.6316.23.04.01.810.1
All Tests0.6410.11.85.71.27.9

The results above show that in general Hibernate with H2 embedded is much 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 embedded database (7.9) reveals that in these tests, Hibernate with H2 embedded is 6.6 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.63) to the normalized speed of Hibernate with H2 embedded database (16.2) reveals that in that case, Hibernate with H2 embedded is 25.7 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 embedded
Hibernate
MySQL server
Hibernate
H2 embedded
Hibernate
MySQL server
Hibernate
H2 embedded
Basic Person Test1.119.71.711.41.415.5
Element Collection Test0.216.90.534.50.375.7
Inheritance Test0.6515.61.812.91.214.2
Indexing Test0.8123.22.012.41.417.8
Graph (Binary Tree) Test0.554.00.624.20.584.1
Multithreading Test0.3527.44.122.72.225.0
All Tests0.6116.11.811.41.213.7

The results above show that in general Hibernate with H2 embedded is much 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 embedded database (13.7) reveals that in these tests, Hibernate with H2 embedded is 11.4 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 embedded database (27.4) reveals that in that case, Hibernate with H2 embedded is 78.3 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 embedded
Hibernate
MySQL server
Hibernate
H2 embedded
Hibernate
MySQL server
Hibernate
H2 embedded
Basic Person Test3.714.23.68.33.611.2
Element Collection Test1.87.20.844.41.35.8
Inheritance Test1.812.24.39.93.111.0
Indexing Test2.016.14.412.83.214.5
Graph (Binary Tree) Test0.837.00.737.70.787.3
Multithreading Test2.119.65.010.93.615.2
All Tests2.112.93.29.02.711.0

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

A huge performance gap has been detected when using graphs of objects with large transaction/retrieval size. Comparing the normalized speed of Hibernate with MySQL database server (0.73) to the normalized speed of Hibernate with H2 embedded database (7.7) reveals that in that case, Hibernate with H2 embedded is 10.5 times faster than Hibernate with MySQL server.

Other Head to Head DBMS/JPA Comparisons