Search code examples
oraclehibernatevert.xhibernate-reactive

Oracle Connnection issue in Hibernate Reactive


I tried to use oracle as db in my hibernate reactive example, but I can not make the connection working well against localhost.

I have tried the following approaches to set up oracle database in the project, all use https://github.com/gvenzl/oci-oracle-free to serve an db instance.

None of above worked, I got error messages like this:

2023-12-23T14:50:19.731+08:00 DEBUG 3548 --- [           main] o.h.r.p.ReactivePersistenceProvider      : Checking persistence-unit [name=blogPU, explicit-provider=org.hibernate.reactive.provider.ReactivePersistenceProvider] against incoming persistence unit name [blogPU]
2023-12-23T14:50:19.749+08:00  INFO 3548 --- [           main] o.hibernate.jpa.internal.util.LogHelper  : HHH000204: Processing PersistenceUnitInfo [name: blogPU]
2023-12-23T14:50:19.906+08:00  INFO 3548 --- [           main] org.hibernate.Version                    : HHH000412: Hibernate ORM core version 6.4.1.Final
2023-12-23T14:50:20.006+08:00  INFO 3548 --- [           main] o.h.c.internal.RegionFactoryInitiator    : HHH000026: Second-level cache disabled
2023-12-23T14:50:20.299+08:00  INFO 3548 --- [           main] o.h.r.pool.impl.DefaultSqlClientPool     : HR000011: SQL Client URL [jdbc:oracle:thin://localhost:1521/blogdb]
2023-12-23T14:50:20.341+08:00 DEBUG 3548 --- [           main] io.vertx.core.logging.LoggerFactory      : Using io.vertx.core.logging.SLF4JLogDelegateFactory
2023-12-23T14:50:20.363+08:00  INFO 3548 --- [           main] o.h.r.vertx.impl.DefaultVertxInstance    : HR000002: Vert.x not detected, creating a new instance
2023-12-23T14:50:20.886+08:00  INFO 3548 --- [           main] .r.p.i.DefaultSqlClientPoolConfiguration : HR000025: Connection pool size: 10
2023-12-23T14:50:24.209+08:00  INFO 3548 --- [ntloop-thread-8] o.h.r.vertx.impl.DefaultVertxInstance    : HR000003: Vert.x instance stopped
2023-12-23T14:50:24.212+08:00  WARN 3548 --- [           main] r.c.GenericReactiveWebApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: 
org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'dataInitializer' 
defined in file [D:\hantsylabs\spring-puzzles\hibernate-reactive-mutiny-oracle\target\classes\com\example\demo\DataInitializer.class]: 
Unsatisfied dependency expressed through constructor parameter 0: Error creating bean with name 'sessionFactory' 
defined in class path resource [com/example/demo/HibernateReactiveConfig.class]: 
Failed to instantiate [org.hibernate.reactive.mutiny.Mutiny$SessionFactory]: 
Factory method 'sessionFactory' threw exception with message:
Unable to create requested service [org.hibernate.engine.jdbc.env.spi.JdbcEnvironment] due to: 
io.vertx.oracleclient.OracleException: ORA-17868: Unknown host specified.: 
No such host is known (oracle)
https://docs.oracle.com/error-help/db/ora-17868/

The example project is here, https://github.com/hantsy/spring-puzzles/tree/master/hibernate-reactive-mutiny-oracle

The connection url configured in persistence.xml: https://github.com/hantsy/spring-puzzles/blob/master/hibernate-reactive-mutiny-oracle/src/main/resources/META-INF/persistence.xml#L11

From the vertx-oracle-client page, connecting to a localhost should work. https://github.com/eclipse-vertx/vertx-sql-client/tree/master/vertx-oracle-client

BTW, the r2dbc connection is working well in the same application. And in IDEA DataSource view(using Jdbc Drivers) oracle database connection via localhost is ok


Solution

  • The Oracle connection string is a little different from MySQL and Postgres( jdbc connection string is jdbc:postgres://localhost:5432/blogdb), when check the Vertx Oracle Client docs, https://vertx.io/docs/4.2.7/vertx-oracle-client/java/ and change jakarta.persistence.jdbc.url property in persistence.xml to the following, it works.

    jdbc:oracle:thin:@localhost:1521/blogdb
    

    Check the completed the persistence.xml here.