Hibernate4

Brett Wooldridge edited this page Aug 5, 2015 · 9 revisions

UPDATE : Hibernate 4.3.6+

As of Hibernate 4.3.6 there is an official ConnectionProvider class from Hibernate, which should be used instead of the HikariCP implementation. The class is called org.hibernate.hikaricp.internal.HikariCPConnectionProvider.


This page is a quick guide to configuring HikariCP in Hibernate 4.x. If you are using an older version of Hibernate (3.x) see the Spring+Hibernate page for configuration. There may be other ways to configure HikariCP with Hibernate, this is just one. If you have additional ideas or methods please post them to the Google group and we'll see about integrating them into this guide.

Thanks to a contribution by Luca Burgazzoli, HikariCP now has a ConnectionProvider for Hibernate 4.x called HikariConnectionProvider. Users of Hibernate 3.x wishing to use the ConnectionProvider, I suggest either following the methods listed above, or copying the HikariConnectionProvider class from the repository into your package. The only thing that changed was some Hibernate package names, so simply fix the imports and you will have a functioning Hibernate 3.x ConnectionProvider.

In order to use the HikariConnectionProvider in Hibernate 4.x add the following property to your hibernate.properties configuration file:

hibernate.connection.provider_class=com.zaxxer.hikari.hibernate.HikariConnectionProvider

You can include HikariCP configuration properties directly in your hibernate.properties file by prefixing the standard HikariCP properties with "hibernate.hikari.", for example:

...
hibernate.connection.provider_class=com.zaxxer.hikari.hibernate.HikariConnectionProvider
hibernate.hikari.minimumIdle=5
hibernate.hikari.maximumPoolSize=10
hibernate.hikari.idleTimeout=30000
hibernate.hikari.dataSourceClassName=com.mysql.jdbc.jdbc2.optional.MysqlDataSource
hibernate.hikari.dataSource.url=jdbc:mysql://localhost/database
hibernate.hikari.dataSource.user=bart
hibernate.hikari.dataSource.password=51mp50n
...

If you are using MySQL, be sure to read the MySQL Configuration Tips.

Thanks again to Luca Burgazzoli for this contribution.

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.