Configure Hibernate with HikariCP

Due to problems with the c3p0 connection pool, I want to see alternatives and decide which one might be more useful in my case. HikariCP looks very promising, but there is no documentation on how to use it with Hibernate.

So far, I am using c3p0 as follows:

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="persistenceUnitName" value="persistenceUnit"/>
    <property name="jpaProperties">
        <props>
            <prop key="hibernate.dialect">${database.dialect}</prop>
            <prop key="hibernate.hbm2ddl.auto">${database.structure}</prop>
            <prop key="hibernate.connection.url">${database.connection}</prop>
            <prop key="hibernate.connection.username">${database.username}</prop>
            <prop key="hibernate.connection.password">${database.password}</prop>
            <prop key="hibernate.connection.driver_class">${database.driver}</prop>
            <prop key="hibernate.connection.shutdown">true</prop>
            <prop key="hibernate.connection.writedelay">0</prop>
            <prop key="hibernate.connection.characterEncoding">UTF-8</prop>
            <prop key="hibernate.connection.charSet">UTF-8</prop>
            <prop key="hibernate.show_sql">${database.show_sql}</prop>
            <prop key="hibernate.format_sql">false</prop>
            <prop key="hibernate.ejb.metamodel.generation">disabled</prop>
            <!-- Use the C3P0 connection pool provider -->
            <prop key="hibernate.connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</prop>
            <prop key="hibernate.c3p0.min_size">5</prop>
            <prop key="hibernate.c3p0.max_size">30</prop>
            <prop key="hibernate.c3p0.timeout">300</prop>
            <prop key="hibernate.c3p0.max_statements">50</prop>
            <prop key="hibernate.c3p0.idle_test_period">600</prop>
        </props>
    </property>

Can someone tell me how to configure HikariCP this way?

+8
source share
3 answers

HikariCP , since version 1.2.6, now supports Hibernate 4.x explicitly using ConnectionProvider. See the new wiki documentation for more details .

+10
source

org.hibernate.hikaricp.internal.HikariCPConnectionProvider, hibernate-hikaricp.

Maven ( ):

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-hikaricp</artifactId>
    <version>5.2.10.Final</version>
</dependency>

hibernate.properties:

'hibernate.connection.provider_class=org.hibernate.hikaricp.internal.HikariCPConnectionProvider'

: Hibernate 4.3.6 com.zaxxer.hikari.hibernate.HikariConnectionProvider (.: https://github.com/brettwooldridge/HikariCP/wiki/Hibernate4)

+18

: . uwolfer, HikariCP Hibernate.

HikariCP. , Spring, Hibernate, :

http://www.luckyryan.com/2013/02/20/spring-mvc-with-basic-persistence-spring-data-jpa-hibernate/

XML , BoneCP mainDataSource, HikariCP.

, , Hibernate Spring DataSource Hibernate, . ( ) , DataSource Spring, Hibernate .

Regarding instruction caching, HikariCP does not do this because we believe that it is best to leave the JDBC provider / DataSource driver. Almost every JDBC DataSourcefor large DB providers provides operator caching, and it can be configured through HikariCP by specifying properties DataSource. Refer to the HikariCP github page to set properties for the primary (provider) DataSource.

+4
source

All Articles