Search code examples
javahibernateconnectionhikaricppooling

ClassCastException HikariCPConnectionProvider cannot be cast to Hibernate ConnectionProvider


I am trying my hands on HikariCP for the first time. I am facing following ClassCastException.

ClassCastException: org.hibernate.hikaricp.internal.HikariCPConnectionProvider cannot be cast to org.hibernate.service.jdbc.connections.spi.ConnectionProvider

UPDATE: I have tried com.zaxxer.hikari.hibernate.HikariConnectionProvider also, and get the same exception.

Here is my config from persistence.xml

<properties>
        <property name="hibernate.connection.provider_class" value="org.hibernate.hikaricp.internal.HikariCPConnectionProvider" />
        <property name="hibernate.hikari.minimumIdle" value="5" />
        <property name="hibernate.hikari.maximumPoolSize" value="10" />
        <property name="hibernate.hikari.idleTimeout" value="30000" />
        <property name="hibernate.hikari.dataSourceClassName" value="com.mysql.jdbc.jdbc2.optional.MysqlDataSource" />
        <property name="hibernate.hikari.dataSource.url" value="jdbc:mysql://localhost:3306/mydb" />
        <property name="hibernate.hikari.dataSource.user" value="dbusr" />
        <property name="hibernate.hikari.dataSource.password" value="pwd" />
    </properties>

I am using following Hibernate and HikariCP versions.

<dependency>
        <groupId>com.zaxxer</groupId>
        <artifactId>HikariCP</artifactId>
        <version>2.4.5</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-hikaricp</artifactId>
        <version>5.1.0.Final</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-core</artifactId>
        <version>5.1.0.Final</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-entitymanager</artifactId>
        <version>5.1.0.Final</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-validator</artifactId>
        <version>5.2.4.Final</version>
    </dependency>

Solution

  • I am sorry that I am responding to my own question after so long. I was facing this issue because I tried to upgrade various hibernate and hikari library versions, which caused my target folder of maven build to have multiple versions of hibernate and hikari causing wrong versions to get picked up. The issue was resolved after cleaning up target and fixing few pom files. Hikari has been doing good since then and also it is very helpful in detecting leaking connections.