Interbase DB:无法创建请求的服务:Hibernate Session

时间:2016-12-06 21:23:56

标签: hibernate session database-connection interbase

在连接到Interbase数据库时,我很难让Hibernate Session工作。我可以通过JDBC连接到数据库,但我不确定为什么我的Session在尝试连接到Interbase时无法实例化。

这是我连接到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>    

  

当我运行代码时,在尝试构建代码的行上抛出异常 的sessionFactory:

configuration.buildSessionFactory();

这是例外:

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

1 个答案:

答案 0 :(得分: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);