将org.hibernate.jpa.hibernatepersistenceprovider与bonecp一起使用时遇到错误

k2fxgqgv  于 2021-06-20  发布在  Mysql
关注(0)|答案(1)|浏览(329)

以前我用过 org.hibernate.ejb.HibernatePersistence 作为提供者类现在我把它改为 org.hibernate.jpa.HibernatePersistenceProvider 因为hibernatepersistence在最新的hibernate版本中不受欢迎。目前我正在使用 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>

我的身材是:

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'
    }

在entitymanagerfactory上调用方法createentitymanager()时发生以下异常。

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

我有个例外 Caused by: java.lang.ClassNotFoundException: Could not load requested class : com.jolbox.bonecp.BoneCPConnectionProvider .
当我查看jar文件内部时,类路径中的jar内部有可用的类。

zd287kbt

zd287kbt1#

因为您使用的是bonecp0.7.1.release,它没有与hibernate版本兼容的bonecpconnectionprovider类。因此,将依赖项更新为0.8.0.release

相关问题