【问题标题】:Interbase DB: Unable to create requested service: Hibernate SessionInterbase DB:无法创建请求的服务:休眠会话
【发布时间】:2016-12-06 21:23:56
【问题描述】:

在连接到 Interbase DB 时,我很难让 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>    

当我运行代码时,尝试构建一个 会话工厂:

configuration.buildSessionFactory();

这里是例外:

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

【问题讨论】:

    标签: hibernate session database-connection interbase


    【解决方案1】:

    我怀疑失败的原因是遗留代码遗留的一些设置。我能收集到的最好的结果是 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);
    

    【讨论】:

      猜你喜欢
      • 2013-12-12
      • 2016-02-09
      • 2020-01-28
      • 2014-12-10
      • 1970-01-01
      • 2014-07-26
      • 2011-06-13
      • 1970-01-01
      相关资源
      最近更新 更多