java.lang.ClassCastException: com.zaxxer.hikari.hibernate.HikariConnectionProvider cannot be cast to org.hibernate.connection.ConnectionProvider

1,796 views
Skip to first unread message

Josef Schnorcher

unread,
Mar 5, 2014, 1:27:14 PM3/5/14
to hika...@googlegroups.com
I'm sure this error is because of my inexperience. However, I hibernate using the default connection pool works fine. The configuration properties are commented in the XML file. But unfortunately, I cant get this working with HikariCP.
I'm using HikariCP:1.3.2 and hibernate-core 4.3.2, ejb3-persistence 1.0.2.GA and the mysql-connector 5.1.29.

Would be great if someone has any idea what I'm doing wrong.

Thanks a lot in advance.
Joe


ERROR connection.ConnectionProviderFactory: Could not instantiate connection provider
java.lang.ClassCastException: com.zaxxer.hikari.hibernate.HikariConnectionProvider cannot be cast to org.hibernate.connection.ConnectionProvider
    at org.hibernate.connection.ConnectionProviderFactory.initializeConnectionProviderFromConfig(ConnectionProviderFactory.java:174)
    at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:102)
    at org.hibernate.connection.ConnectionProviderFactory.newConnectionProvider(ConnectionProviderFactory.java:84)
    at org.hibernate.cfg.SettingsFactory.createConnectionProvider(SettingsFactory.java:438)
    at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:91)
    at org.hibernate.cfg.Configuration.buildSettingsInternal(Configuration.java:2163)
    at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2159)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1383)
    at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:954)

The Java code
SessionFactory sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
            Session session = sessionFactory.openSession();

            MyProject  myProject= (MyProject) session.get(MyProject.class,1l);

Hibernate.cfg.xml
<hibernate-configuration>
    <session-factory>

        <!--
        <property name="connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="connection.url">jdbc:mysql://myhostname:3306/mydatabasetest</property>
        <property name="connection.username">user</property>
        <property name="connection.password">password</property>     -->

        <property name="hibernate.connection.provider_class">com.zaxxer.hikari.hibernate.HikariConnectionProvider</property>
        <property name="hibernate.hikari.dataSourceClassName">com.mysql.jdbc.jdbc2.optional.MysqlDataSource</property>
        <property name="hibernate.hikari.minimumPoolSize">2</property>
        <property name="hibernate.hikari.maximumPoolSize">100</property>
        <property name="hibernate.hikari.idleTimeout">30000</property>
        <property name="hibernate.hikari.dataSource.url">jdbc:mysql://myhostname:3306/mydatabasetest</property>
        <property name="hibernate.hikari.dataSource.user">user</property>
        <property name="hibernate.hikari.dataSource.password">password</property>
        <property name="hibernate.hikari.dataSource.cachePrepStmts">true</property>
        <property name="hibernate.hikari.dataSource.prepStmtCacheSize">250</property>
        <property name="hibernate.hikari.dataSource.prepStmtCacheSqlLimit">2048</property>
        <property name="hibernate.hikari.dataSource.useServerPrepStmts">true</property>

        <property name="dialect">org.hibernate.dialect.MySQLDialect</property>

        <property name="current_session_context_class">thread</property>
        <property name="show_sql">true</property>
        <property name="hbm2ddl.auto">validate</property>
        <mapping class="org.test.model.MyProject"/>
    </session-factory>
</hibernate-configuration>

Brett Wooldridge

unread,
Mar 5, 2014, 6:08:21 PM3/5/14
to hika...@googlegroups.com
If you Google "cannot be cast to org.hibernate.connection.ConnectionProvider" you'll find lots of similar issues and solutions.  It is a configuration error, but the solution depends upon your application container.

-Bret

Josef Schnorcher

unread,
Mar 6, 2014, 1:36:06 PM3/6/14
to hika...@googlegroups.com
Thanks for your hint. After removing the included lib: hibernate:hibernate-annotations:3.5.6-Final everything works fine. 

Joe
Reply all
Reply to author
Forward
0 new messages