Hibernate
Hibernate Performance Summary
The following charts show the performance of Hibernate (in green) relatively to other JPA/DBMS combinations (in gray).
Position #1 on the X-Axis (the fastest) is about 100 times faster than position #33 (the slowest).
The configurations in which Hibernate has been tested are listed in the following table:
Database + JPA Provider | Normalized Score 100 - Best, 0 - Worst | Final Position 1 - Best, 33 - Worst | Failed Tests | |
---|---|---|---|---|
1 | Hibernate with HSQLDB embedded | 13.9 | 5 (out of 33) | 0 |
2 | Hibernate with H2 embedded | 11.0 | 7 (out of 33) | 0 |
3 | Hibernate with PostgreSQL server | 9.1 | 11 (out of 33) | 0 |
4 | Hibernate with Derby embedded | 8.3 | 12 (out of 33) | 0 |
5 | Hibernate with Derby server | 5.6 | 20 (out of 33) | 0 |
6 | Hibernate with H2 server | 3.4 | 23 (out of 33) | 0 |
7 | Hibernate with MySQL server | 2.7 | 28 (out of 33) | 0 |
8 | Hibernate with SQLite embedded | 0.62 | 32 (out of 33) | 14 |
About Hibernate
Hibernate is the most popular object-relational mapping (ORM) library for Java. It was first released in 2002 by Gavin King, who later joined JBoss with Hibernate. In 2006 JBoss has been acquired by Red Hat that now owns also Hibernate.
Hibernate is available under the LGPL open source license.
In this benchmark Hibernate version 4.1 (which was released in February 2012) has been tested.
Hibernate Performance Tuning
The Hibernate default configuration is generally optimized for high performance, and works very well also with no tuning.
To maximize performance we followed the Hibernate Core and the Hibernate EntityManager instructions:
-
Database dialects have been defined using the
hibernate.dialect
property. -
The
javax.persistence.validation.mode
property was set toNONE
. -
The c3p0 connection pool was enabled by setting the
hibernate.c3p0.*
properties. -
The
hibernate.order_updates
property was set totrue
. -
The
hibernate.id.new_generator_mappings
property was set totrue
. -
The
hibernate.jdbc.fetch_size
property was set to100
. -
The
hibernate.jdbc.batch_size
property was set to30
and thehibernate.jdbc.batch_versioned_data
property was set totrue
. -
The
hibernate.connection.release_mode
property was set toon_close
. -
The
hibernate.bytecode.use_reflection_optimizer
property was set totrue
and thehibernate.bytecode.provider
property was set tojavassist
. - Logging was disabled.
Note: Database schema generation was completed before time measurement started.
Solved Problems and Issues
The stack traces below demonstrate some exceptions that have been thrown when using Hibernate in previous runs of this benchmark and have been fixed by upgrading software and setting.
javax.persistence.PersistenceException: org.hibernate.exception.SQLGrammarException: could not execute query at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1235) at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1168) at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:250) at org.jpab.node.NodeTest.retireveEntities(NodeTest.java:130) at org.jpab.Test.doAction(Test.java:250) at org.jpab.Runner$RetrieveAction.run0(Runner.java:540) at org.jpab.Runner$TestAction.run(Runner.java:507) at java.lang.Thread.run(Thread.java:619) Caused by: org.hibernate.exception.SQLGrammarException: could not execute query at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:92) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66) at org.hibernate.loader.Loader.doList(Loader.java:2452) at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2192) at org.hibernate.loader.Loader.list(Loader.java:2187) at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:452) at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:363) at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:196) at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1258) at org.hibernate.impl.QueryImpl.list(QueryImpl.java:102) at org.hibernate.ejb.QueryImpl.getResultList(QueryImpl.java:241) ... 5 more Caused by: java.sql.SQLException: data type cast needed for parameter or null literal at org.hsqldb.jdbc.Util.sqlException(Unknown Source) at org.hsqldb.jdbc.JDBCPreparedStatement.(Unknown Source) at org.hsqldb.jdbc.JDBCConnection.prepareStatement(Unknown Source) at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:534) at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:452) at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:161) at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1616) at org.hibernate.loader.Loader.doQuery(Loader.java:717) at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:270) at org.hibernate.loader.Loader.doList(Loader.java:2449) ... 13 more Caused by: org.hsqldb.HsqlException: data type cast needed for parameter or null literal at org.hsqldb.error.Error.error(Unknown Source) at org.hsqldb.error.Error.error(Unknown Source) at org.hsqldb.FunctionSQL.resolveTypes(Unknown Source) at org.hsqldb.ExpressionLogical.resolveTypes(Unknown Source) at org.hsqldb.ExpressionLogical.resolveTypes(Unknown Source) at org.hsqldb.QuerySpecification.resolveExpressionTypes(Unknown Source) at org.hsqldb.QuerySpecification.resolveTypesPartOne(Unknown Source) at org.hsqldb.QuerySpecification.resolveTypes(Unknown Source) at org.hsqldb.QueryExpression.resolve(Unknown Source) at org.hsqldb.ParserDQL.compileCursorSpecification(Unknown Source) at org.hsqldb.ParserCommand.compilePart(Unknown Source) at org.hsqldb.ParserCommand.compileStatement(Unknown Source) at org.hsqldb.Session.compileStatement(Unknown Source) at org.hsqldb.StatementManager.compile(Unknown Source) at org.hsqldb.Session.execute(Unknown Source) ... 22 more
javax.persistence.RollbackException: Error while committing the transaction at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:93) at org.jpab.Test.doAction(Test.java:271) at org.jpab.Runner$UpdateAction.run0(Runner.java:564) at org.jpab.Runner$TestAction.run(Runner.java:507) at java.lang.Thread.run(Thread.java:619) Caused by: javax.persistence.PersistenceException: org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1235) at org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1168) at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:81) ... 4 more Caused by: org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:140) at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:128) at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:66) at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:275) at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:262) at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:179) at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:321) at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:51) at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:1206) at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:375) at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:137) at org.hibernate.ejb.TransactionImpl.commit(TransactionImpl.java:76) ... 4 more Caused by: java.sql.BatchUpdateException: Batch entry 1 update Person set birthDate='1956-09-15 +03:00:00', city='XPCNOZUAKIJBQIVW', country='GTKNV', email='[email protected]', firstName='VPAQHJRNT', joinDate='1979-03-05 +02:00:00', lastLoginDate='2010-09-09 +03:00:00', lastName='FIKXUBCDSP', loginCount='173', middleName='QGAXGU', phone='221668502734689', state='DP', street='UPPDCMHIQXS', zip='456616781' where id='107279' was aborted. Call getNextException to see the cause. at org.postgresql.jdbc2.AbstractJdbc2Statement$BatchResultHandler.handleError(AbstractJdbc2Statement.java:2569) at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:1796) at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:407) at org.postgresql.jdbc2.AbstractJdbc2Statement.executeBatch(AbstractJdbc2Statement.java:2708) at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:70) at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:268) ... 12 more
java.lang.NoSuchFieldError: STRING at dialect.SQLiteDialect.(SQLiteDialect.java:46) at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27) at java.lang.reflect.Constructor.newInstance(Constructor.java:513) at java.lang.Class.newInstance0(Class.java:355) at java.lang.Class.newInstance(Class.java:308) at org.hibernate.dialect.resolver.DialectFactory.constructDialect(DialectFactory.java:156) at org.hibernate.dialect.resolver.DialectFactory.buildDialect(DialectFactory.java:99) at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:130) at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2833) at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2829) at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1840) at org.hibernate.ejb.Ejb3Configuration.buildEntityManagerFactory(Ejb3Configuration.java:902) at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:57) at javax.persistence.Persistence.createEntityManagerFactory(Unknown Source) at javax.persistence.Persistence.createEntityManagerFactory(Unknown Source) at org.jpab.Runner.handleAction(Runner.java:285) at org.jpab.Runner.run(Runner.java:248) at org.jpab.Runner.main(Runner.java:78)