Keycloak Docker - Oracle Connection Problem

Hi,

Trying to start keycloak using a Oracle DB, found that can’t connect using the Service Name.
It’s only possible using SID.

I need to connect using Service Name, so I did a small change on this file to support it.


We need to change line 2:

/subsystem=datasources/data-source=KeycloakDS: add(jndi-name=java:jboss/datasources/KeycloakDS,enabled=true,use-java-context=true,use-ccm=true, connection-url=jdbc:oracle:thin:@{env.DB_ADDR:oracle}:{env.DB_PORT:1521}:{env.DB_DATABASE:XE}{env.JDBC_PARAMS:}, driver-name=oracle)

to
/subsystem=datasources/data-source=KeycloakDS: add(jndi-name=java:jboss/datasources/KeycloakDS,enabled=true,use-java-context=true,use-ccm=true, connection-url=jdbc:oracle:thin:@//{env.DB_ADDR:oracle}:{env.DB_PORT:1521}/{env.DB_DATABASE:XE}{env.JDBC_PARAMS:}, driver-name=oracle)

That’s it. It’s working.

Another thing.
Changed keycloak version from 8.0.0 to 10.0.2.

I need to do something more to have the last correct version of Docker Distribution?

Thanks,
JP

1 Like

Hi Thanks for this update, very useful.
did you however encounter :
database: oracle
version: 18c
jdbc

Caused by: org.hibernate.HibernateException: **Access to DialectResolutionInfo cannot be null when 'hibernate.dialect' not set**
	at org.hibernate@5.3.12.Final//org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.determineDialect(DialectFactoryImpl.java:100)
	at org.hibernate@5.3.12.Final//org.hibernate.engine.jdbc.dialect.internal.DialectFactoryImpl.buildDialect(DialectFactoryImpl.java:54)
	at org.hibernate@5.3.12.Final//org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:137)
	at org.hibernate@5.3.12.Final//org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35)
	at org.hibernate@5.3.12.Final//org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:94)
	at org.hibernate@5.3.12.Final//org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:263)

Hi.

No, I don’t receive any error.

This is how was before:
jdbc:oracle:thin:@hostname:1521:XE

And now added the “//” and changed the “:” to “/” to connect to a service.

jdbc:oracle:thin:@//hostname:1521/xepdb1

Thanks,
JP

with this change works great.

Thanks jpvadell for the swift response.

I eventually resolved it:
I updated the change-database.cli. – see the line in bold for anyone interested

/subsystem=datasources/data-source=KeycloakDS: remove()
/subsystem=datasources/data-source=KeycloakDS: add(jndi-name=java:jboss/datasources/KeycloakDS,enabled=true,use-java-context=true,use-ccm=true, connection-url=jdbc:oracle:thin:@//{env.DB_ADDR:oracle}:{env.DB_PORT:1521}/{env.DB_DATABASE:XE}{env.JDBC_PARAMS:}, driver-name=oracle)
/subsystem=datasources/data-source=KeycloakDS: write-attribute(name=user-name, value={env.DB_USER:SYSTEM}) /subsystem=datasources/data-source=KeycloakDS: write-attribute(name=password, value={env.DB_PASSWORD:oracle})
/subsystem=datasources/data-source=KeycloakDS: write-attribute(name=check-valid-connection-sql, value=“SELECT 1 FROM dual”)
/subsystem=datasources/data-source=KeycloakDS: write-attribute(name=background-validation, value=true)
/subsystem=datasources/data-source=KeycloakDS: write-attribute(name=background-validation-millis, value=60000)
/subsystem=datasources/data-source=KeycloakDS: write-attribute(name=flush-strategy, value=IdleConnections)
/subsystem=datasources/data-source=KeycloakDS: write-attribute(name=hibernate.dialect, value=org.hibernate.dialect.Oracle18cDialect)
/subsystem=datasources/jdbc-driver=oracle:add(driver-name=oracle, driver-module-name=com.oracle.jdbc8, driver-xa-datasource-class-name=oracle.jdbc.xa.client.OracleXADataSource)