2016-12-06 124 views
0

連接到Interbase DB時,我很難讓Hibernate Session工作。我可以通過JDBC連接到數據庫,但我不確定爲什麼我的會話在嘗試連接到Interbase時未能實例化。Interbase DB:無法創建請求的服務:休眠會話

這裏是我的方法的提取物來連接到Interbase的:

database connection: 
URL configLoc = this.getClass().getResource("/resources/hibernate.cfg.xml"); 
Properties props = new Properties(); 
try { 
    databaseName = "jdbc:interbase://v-ib/e:/db/44june.gdb"; 
    configuration = new Configuration().configure(configLoc); 
    configuration.setProperty("hibernate.connection.url", databaseName); 
    configuration.setProperty("hibernate.connection.username", "HOST"); 
    configuration.setProperty("hibernate.connection.password", "HOST"); 
    try{ 
     sessionFactory = configuration.buildSessionFactory(); 
    } catch (Exception e2){ 
    System.out.println(e2.getMessage()); 
    } 
    } 
} 
database = sessionFactory.createEntityManager(); 

...這是我的hibernate.cfg.xml:

Hibernate.cfg.xml : 

<hibernate-configuration> 
<session-factory> 
    <property  
    name="hibernate.dialect">org.hibernate.dialect.InterbaseDialect</property> 
    <property 
name="hibernate.connection.driver_class">interbase.interclient.Driver</property> 
<property name="hibernate.show_sql">true</property> 
<property name="hibernate.connection.pool_size">1</property> 
<property name="hibernate.jdbc.use_scrollable_resultset">true</property>  

當我運行代碼,嘗試構建會話的線路上會引發異常工廠:

configuration.buildSessionFactory();

和這裏的例外:

Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment]

回答

0

我懷疑這是失敗是從遺留代碼遺留下來的一些設置的原因。我可以收集的最好的是Interbase類和方言沒有從hibernate.cfg.xml正確加載。向try {}塊中添加以下行似乎有訣竅:

String dialect = "org.hibernate.dialect.InterbaseDialect"; 
String driverClass = "interbase.interclient.Driver"; 
configuration.setProperty("hibernate.connection.dialect", dialect); 
configuration.setProperty("hibernate.connection.driver_class", 
    driverClass);