小编典典

找不到Hibernate 4 ConnectionProvider类

hibernate

我刚刚将应用程序中的Hibernate更新为4.3.4(从3.X),这引起了一些问题。第一个是我解决的创建sessionFactory的新方法。

我没有发现的下一个问题是,我现在在org.hibernate.connection.ConnectionProvider上收到ClassNotFoundException

应该注意的是,我在连接池中使用的是BoneCP(0.7.1),该连接池在升级之前就可以使用了。

任何帮助,将不胜感激。我刚进入hibernate状态(我正在努力将其实现为POC),因此我可能在这里的描述中遗漏了一些重要的细节。我不需要它是最新版本,因此我可以还原,但是拥有最新,最出色的版本将非常不错:)

谢谢!

Hibernate.cfg.xml代码段(已替换敏感信息):

<hibernate-configuration>
    <session-factory>
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="hibernate.connection.url">foo</property>
        <property name="hibernate.connection.username">bob</property>
        <property name="hibernate.default_schema">bar</property>
        <property name="hibernate.dialect">package.path.MySQLCustomDialect</property>

        <!-- Bonecp connection pool -->
        <property name="hibernate.connection.provider_class">com.jolbox.bonecp.provider.BoneCPConnectionProvider</property>
        <property name="bonecp.maxConnectionAgeInMinutes">5</property>
        <property name="bonecp.idleConnectionTestPeriodInMinutes">0</property>
        and so on ...

堆栈跟踪:

Exception in thread "Thread-110" java.lang.NoClassDefFoundError: org/hibernate/connection/ConnectionProvider
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClassCond(ClassLoader.java:637)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:621)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
    at org.apache.catalina.loader.WebappClassLoader.findClassInternal(WebappClassLoader.java:2895)
    at org.apache.catalina.loader.WebappClassLoader.findClass(WebappClassLoader.java:1173)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1681)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
    at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl$AggregatedClassLoader.findClass(ClassLoaderServiceImpl.java:222)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:249)
    at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:240)
    at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.selectStrategyImplementor(StrategySelectorImpl.java:125)
    at org.hibernate.engine.jdbc.connections.internal.ConnectionProviderInitiator.instantiateExplicitConnectionProvider(ConnectionProviderInitiator.java:194)
    at org.hibernate.engine.jdbc.connections.internal.ConnectionProviderInitiator.initiateService(ConnectionProviderInitiator.java:120)
    at org.hibernate.engine.jdbc.connections.internal.ConnectionProviderInitiator.initiateService(ConnectionProviderInitiator.java:55)
    at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:83)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:223)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:197)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:178)
    at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.buildJdbcConnectionAccess(JdbcServicesImpl.java:260)
    at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:94)
    at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:89)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:206)
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:178)
    at org.hibernate.cfg.Configuration.buildTypeRegistrations(Configuration.java:1885)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1843)
    at foo.utils.HibernateUtils.<clinit>(HibernateUtils.java:16)
    at foo.objects.building.BuildingHelper.getBuildingByID(BuildingHelper.java:225)
    at foo.objects.inventory.LocationInformation.<init>(LocationInformation.java:36)
    at foo.objects.computermanagementframework.peripheral.PeripheralHelper.readLocation(PeripheralHelper.java:154)
    at foo.objects.computermanagementframework.peripheral.PeripheralHelper.refresh(PeripheralHelper.java:556)
    at foo.server.initialization.InitializeServerThread.run(InitializeServerThread.java:298)
    at java.lang.Thread.run(Thread.java:695)
Caused by: java.lang.ClassNotFoundException: org.hibernate.connection.ConnectionProvider
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
    ... 36 more

阅读 492

收藏
2020-06-20

共1个答案

小编典典

Hibernate不断更改包含ConnectionProvider基类的包。它从版本3更改为版本4,并在版本4.3中再次更改。正如@ teresa-
carrigan在对此答案的评论中提到的那样,您必须编译最新的BoneCPConnectionProvider.java(当前支持Hibernate
4.3.1)并使用它。
或者使用Hibernate 4.2.12.Final版本,看看它是否适用于BoneCP 0.8(如上述答案中所述)。

2020-06-20