找不到Hibernate 4 ConnectionProvider类

时间:2014-04-11 16:42:37

标签: java hibernate exception classnotfoundexception

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

我没有发现任何问题的下一个问题是我现在在org.hibernate.connection.ConnectionProvider上获得了ClassNotFoundException

应该注意的是,我使用BoneCP(0.7.1)作为我的连接池,它在升级之前正在运行。

任何帮助将不胜感激。我很熟悉hibernate(我正在努力将其作为POC实现),而我可能已经从我的描述中遗漏了一些重要细节。 我不需要它成为最新版本,所以我可以回复,但拥有最新最好的版本会很好:)(/ p>

谢谢!

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

1 个答案:

答案 0 :(得分:4)

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