JDBC THIN URL出现HibernateReact错误

v6ylcynt  于 2022-11-24  发布在  React
关注(0)|答案(1)|浏览(159)

我正在尝试使用Oracle 19 c进行休眠React。当我发送如下URL时,我收到一个错误,似乎是字符串限制。我如何解决这个问题?
数据库URL:“jdbc:oracle:thin:@(说明=(启用=中断)(地址=(协议=tcp)(主机=本地主机)(端口=1521))(连接数据=(SID=ORCLCDB))”
错误:工厂方法“sessionFactory”引发了异常;嵌套的异常是java.lang.StringIndexOutOfBoundsException:开始0,结束-1,长度108
下面是我的代码

public Mutiny.SessionFactory sessionFactory() {
  org.hibernate.cfg.Configuration configuration = constructConfiguration();
  StandardServiceRegistryBuilder builder = new ReactiveServiceRegistryBuilder().applySettings( configuration.getProperties() );
  StandardServiceRegistry registry = builder.build();
  return configuration.buildSessionFactory( registry ).unwrap( Mutiny.SessionFactory.class );
}

private org.hibernate.cfg.Configuration constructConfiguration() {
  org.hibernate.cfg.Configuration configuration = new org.hibernate.cfg.Configuration();

  entityTypes().forEach(configuration::addAnnotatedClass);

  // set DB info
  configuration.setProperty(Settings.DRIVER, "oracle.jdbc.driver.OracleDriver"));
  // it works
  configuration.setProperty(Settings.URL,"jdbc:oracle:thin:@localhost:1521/ORCLCDB");
  // it raises the error
  // configuration.setProperty(Settings.URL,"jdbc:oracle:thin:@(DESCRIPTION=(ENABLE=BROKEN)(ADDRESS=(PROTOCOL=tcp)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SID=ORCLCDB)))");
  configuration.setProperty(Settings.USER, "user"));
  configuration.setProperty(Settings.PASS, "1234"));

  return configuration;
}

private Collection<Class<?>> entityTypes() {
  List<Class<?>> list = new ArrayList<>();
  list.add(TestEntity.class);
  return list;
}
rggaifut

rggaifut1#

我认为Hibernate Reactive目前还不能解析这种类型的URL。
在下面,Hibernate Reactive使用Vert.x SQL客户端。一个解决方法是自己配置驱动程序,实现SqlClientPoolConfiguration接口,并通过ServiceContributor将其作为服务添加到。
该过程与VertxInstance文档中描述的过程相同:
1.创建扩展DefaultSqlClientPoolConfiguration的类
1.覆盖方法connectOptions(URI uri)

public class MyOracleClientPool extends DefaultSqlClientPoolConfiguration {

    @Override
    public SqlConnectOptions connectOptions(URI uri) {
        // Create your own SqlConnectOptions object 
    }
}

1.创建服务参与者:

public class MyServiceContributor implements ServiceContributor {

   @Override
   public void contribute(StandardServiceRegistryBuilder serviceRegistryBuilder) {
      serviceRegistryBuilder.addService( SqlClientPoolConfiguration.class, new MyOracleClientPool() );
   }
}

1.将名为org.hibernate.service.spi.ServiceContributor的文本文件添加到/META-INF/services/

org.myproject.MyServiceContributor

有关SqlClientPoolOptions的一些信息,请参阅Vert.x SQL Client for Oracle的文档。

相关问题