2014-04-11 83 views
4

我剛剛更新了我的應用程序中的休眠到4.3.4(從3.X),這造成了一些問題。第一個是創建sessionFactory的新方法,我解決了這個問題。休眠4 ConnectionProvider類沒有找到

下一個問題,我發現無事,是我現在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 
+0

您是否使用maven構建項目? – lakshman

+0

是在構建路徑中包含類「com.jolbox.bonecp.provider.BoneCPConnectionProvider」的庫(jar)嗎? – sakura

+0

是的,這是一個maven項目。我在我的構建路徑中有bonecp-0.8.0.RELEASE和bonecp-provider-0.7.1.RELEASE(也是maven依賴項) – thepoynt

回答

4

休眠不斷變化包含ConnectionProvider基類中的包。它從版本3更改爲4,並且使用版本4.3再次更改。 As @ teresa-carrigan在this answer的評論中提到,您必須編譯最新的BoneCPConnectionProvider.java(目前支持Hibernate 4.3.1)並使用它。
或者使用Hibernate 4.2.12.Final版本,看看它是否適用於BoneCP 0.8(正如前面提到的答案中所解釋的)。

+0

回到4.2.10,BoneCP 0.8正常工作。謝謝你的提示! – thepoynt