简体   繁体   中英

Encounter error while using org.hibernate.jpa.HibernatePersistenceProvider with BoneCP

Previously i am using org.hibernate.ejb.HibernatePersistence as provider class now i changed it to org.hibernate.jpa.HibernatePersistenceProvider because HibernatePersistence is deprecated in latest hibernate version. Currently i am using hibernate 5.3.2.Final .

My persistence.xml :

<?xml version="1.0" encoding="UTF-8"?>

    <persistence xmlns="http://java.sun.com/xml/ns/persistence"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
        http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
        version="1.0">

        <persistence-unit name="iTest" transaction-type="RESOURCE_LOCAL">
            <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>
            <class>com.test.Test</class>
            <exclude-unlisted-classes>true</exclude-unlisted-classes>
            <properties>
                <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver" />
                <property name="hibernate.dialect" value="org.hibernate.dialect.MySQLDialect" />
                <property name="hibernate.connection.username" value="root" />
                <property name="hibernate.connection.password" value="root" />
                <property name="hibernate.jdbc.batch_size" value="1000" />

                <property name="hibernate.format_sql" value="false" />
                <property name="hibernate.show_sql" value="false" />
                <property name="hibernate.use_sql_comments" value="false" />
                <property name="hibernate.hbm2ddl.auto" value="update" />

                <property name="hibernate.connection.provider_class" value="com.jolbox.bonecp.provider.BoneCPConnectionProvider" />
                <property name="bonecp.idleConnectionTestPeriod" value="60" />
                <property name="bonecp.partitionCount" value="3" />
                <property name="bonecp.maxConnectionsPerPartition" value="60" />
                <property name="bonecp.minConnectionsPerPartition" value="20" />
                <property name="bonecp.statementsCacheSize" value="100" />
                <property name="bonecp.releaseHelperThreads" value="3" />
            </properties>
        </persistence-unit>

    </persistence>

My build.gradle is :

dependencies {
        compile group: 'com.opencsv', name: 'opencsv', version:'4.2'
        compile group: 'org.apache.logging.log4j', name: 'log4j-core', version:'2.11.0'
        compile group: 'org.apache.commons', name: 'commons-lang3', version:'3.7'
        compile group: 'org.springframework', name: 'spring-context', version:'5.0.7.RELEASE'
        compile group: 'org.springframework', name: 'spring-orm', version:'5.0.7.RELEASE'
        compile(group: 'org.hibernate', name: 'hibernate-core', version:'5.3.2.Final') {
            exclude(module: 'slf4j-api')
            exclude(module: 'slf4j-api')
            exclude(module: 'cglib')
            exclude(module: 'xml-apis')
        }
        compile group: 'org.apache.commons', name: 'commons-pool2', version:'2.5.0'
        compile group: 'org.slf4j', name: 'slf4j-api', version:'1.7.25'
        compile group: 'org.slf4j', name: 'slf4j-log4j12', version:'1.7.25'
        compile group: 'org.springframework', name: 'spring-aspects', version:'5.0.7.RELEASE'
        /*compile group: 'org.hibernate', name: 'hibernate-annotations', version:'3.5.6-Final'*/
        compile group: 'mysql', name: 'mysql-connector-java', version:'8.0.11'
        compile group: 'org.aspectj', name: 'aspectjrt', version:'1.9.1'
        compile group: 'org.aspectj', name: 'aspectjweaver', version:'1.9.1'
        compile group: 'org.apache.commons', name: 'commons-configuration2', version:'2.2'
        compile(group: 'com.jolbox', name: 'bonecp', version:'0.8.0.RELEASE') {
            exclude(module: 'slf4j-api')
        }
        compile(group: 'com.jolbox', name: 'bonecp-provider', version:'0.7.1.RELEASE') {
            exclude(module: 'slf4j-api')
        }
        compile group: 'com.google.guava', name: 'guava', version:'25.1-jre'
        compile group: 'com.googlecode.json-simple', name: 'json-simple', version:'1.1.1'
        testCompile group: 'junit', name: 'junit', version:'4.10'
    }

While calling method createEntityManager() on EntityManagerFactory getting below exception.

Caused by: org.hibernate.boot.registry.selector.spi.StrategySelectionException: Unable to resolve name [com.jolbox.bonecp.BoneCPConnectionProvider] as strategy [org.hibernate.engine.jdbc.connections.spi.ConnectionProvider]
        at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.selectStrategyImplementor(StrategySelectorImpl.java:133)
        at org.hibernate.engine.jdbc.connections.internal.ConnectionProviderInitiator.initiateService(ConnectionProviderInitiator.java:138)
        at org.hibernate.engine.jdbc.connections.internal.ConnectionProviderInitiator.initiateService(ConnectionProviderInitiator.java:41)
        at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:94)
        at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:263)
        ... 24 more
    Caused by: org.hibernate.boot.registry.classloading.spi.ClassLoadingException: Unable to load class [com.jolbox.bonecp.BoneCPConnectionProvider]
        at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:354)
        at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.selectStrategyImplementor(StrategySelectorImpl.java:129)
        ... 28 more
    Caused by: java.lang.ClassNotFoundException: Could not load requested class : com.jolbox.bonecp.BoneCPConnectionProvider
        at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl$AggregatedClassLoader.findClass(ClassLoaderServiceImpl.java:342)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        at java.lang.Class.forName0(Native Method)
        at java.lang.Class.forName(Class.java:348)
        at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:351)
        ... 29 more

I am getting exception Caused by: java.lang.ClassNotFoundException: Could not load requested class : com.jolbox.bonecp.BoneCPConnectionProvider .

When i look inside jar file there is class available inside jar in classpath.

As you are using bonecp 0.7.1.RELEASE which doesn't have the BoneCPConnectionProvider class which is compatible with your hibernate version. so update the dependency to 0.8.0.RELEASE

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM