2017-04-12 28 views
0

我將Hibernate 5與MSSQL 2012連接起來。我能夠與Java(主法)成功連接。但是,當我部署在Karaf,它給我的錯誤:HIbernate與karaf和MS-sql不起作用

Caused by: org.hibernate.boot.registry.classloading.spi.ClassLoadingException: Unable to load class [net.sourceforge.jtds.jdbc.Driver] 
    at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:229) 
    at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.loadDriverIfPossible(DriverManagerConnectionProviderImpl.java:183) 
    at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.buildCreator(DriverManagerConnectionProviderImpl.java:139) 
    at org.hibernate.engine.jdbc.connections.internal.DriverManagerConnectionProviderImpl.configure(DriverManagerConnectionProviderImpl.java:78) 
    at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:94) 
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:217) 
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:189) 
    at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.buildJdbcConnectionAccess(JdbcEnvironmentInitiator.java:145) 
    at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:66) 
    at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35) 
    at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:88) 
    at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:234) 
    ... 61 more 
Caused by: java.lang.ClassNotFoundException: Could not load requested class : net.sourceforge.jtds.jdbc.Driver 
    at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl$AggregatedClassLoader.findClass(ClassLoaderServiceImpl.java:217) 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)[:1.8.0_51] 
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)[:1.8.0_51] 
    at java.lang.Class.forName0(Native Method)[:1.8.0_51] 
    at java.lang.Class.forName(Class.java:348)[:1.8.0_51] 
    at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:226) 

這是我hibernate.cfg文件:

<hibernate-configuration> 
    <session-factory> 
    <property name="hibernate.connection.driver_class">net.sourceforge.jtds.jdbc.Driver</property> 
    <property name="hibernate.connection.url">jdbc:jtds:sqlserver://<ip>:<port>/<dbname></property> 
    <property name="hibernate.connection.username">testuser</property> 
    <property name="hibernate.connection.password">abc</property> 

    <property name="hibernate.dialect">org.hibernate.dialect.SQLServerDialect</property> 


    </session-factory> 
</hibernate-configuration> 

我在karaf中安裝該功能爲:

wrap:mvn:net.sourceforge.jtds/jtds/1.3.1 

但仍然存在錯誤。該存儲庫還包含類(Driver.class),但我仍然得到這個錯誤。可以幫助我找出任何一個問題?我錯過了什麼?

回答

1

一般在OSGi中使用Driver.class加載jdbc驅動程序不起作用。 相反,你應該使用pax-jdbc-config來提供一個作爲OSGi服務的數據源和Aries JPA來使得休眠完全OSGi就緒。

我還沒有使用MS-SQL,但pax-jdbc也支持它。所以它通常應該工作。

有關完整的示例,請參見tasklist-ds