Keycloak persistence.xml with quarkus.properties

Hi all, I am currently stuck while trying to get my persistence.xml to read the datasource’s details from the quarkus.properties I have set up, based on keycloak-quickstarts/user-storage-jpa at latest · keycloak/keycloak-quickstarts · GitHub.

I am in a docker environment, so assuming I got it right, I placed the quakus.properties within a folder that is mapped to /opt/keycloak/conf, in order to have them in the location mentioned in the GitHub example above-linked.

Find below my quarkus.properties

quarkus.datasource.mydb.db-kind=mariadb
quarkus.datasource.mydb.username=user
quarkus.datasource.mydb.password=pass
quarkus.datasource.mydb.jdbc.url=jdbc:mariadb://db:3306/mydb?characterEncoding=UTF-8

And the snippet of the persistence.xml

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0"
             xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd">
  <persistence-unit name="mydb" transaction-type="JTA">
    
    <class>
       My classes here...
    </class>

    <properties>
      <property name="hibernate.dialect" value="org.hibernate.dialect.MariaDB102Dialect"/>
      <property name="hibernate.connection.datasource" value="mydb"/>
      <property name="javax.persistence.transactionType" value="JTA"/>
      <property name="hibernate.hbm2ddl.auto" value="none"/>
    </properties>
  </persistence-unit>
</persistence>

Finally, here’s the error I get as soon as the Docker container starts:

2022-09-08 10:35:18,157 WARN  [org.hibernate.engine.jdbc.connections.internal.ConnectionProviderInitiator] (JPA Startup Thread: idp) HHH000181: No appropriate connection provider encountered, assuming application will be supplying connections

2022-09-08 10:35:18,158 WARN  [org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator] (JPA Startup Thread: idp) HHH000342: Could not obtain connection to query metadata: java.lang.UnsupportedOperationException: The application must supply JDBC connections

at org.hibernate.engine.jdbc.connections.internal.UserSuppliedConnectionProviderImpl.getConnection(UserSuppliedConnectionProviderImpl.java:44)

at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator$ConnectionProviderJdbcConnectionAccess.obtainConnection(JdbcEnvironmentInitiator.java:181)

at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:68)

at org.hibernate.engine.jdbc.env.internal.JdbcEnvironmentInitiator.initiateService(JdbcEnvironmentInitiator.java:35)

at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:101)

at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:263)

at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:237)

at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:214)

at org.hibernate.engine.jdbc.internal.JdbcServicesImpl.configure(JdbcServicesImpl.java:51)

at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.configureService(StandardServiceRegistryImpl.java:107)

at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:246)

at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:214)

at org.hibernate.boot.internal.SessionFactoryOptionsBuilder.<init>(SessionFactoryOptionsBuilder.java:272)

at io.quarkus.hibernate.orm.runtime.recording.PrevalidatedQuarkusMetadata.buildSessionFactoryOptionsBuilder(PrevalidatedQuarkusMetadata.java:68)

at io.quarkus.hibernate.orm.runtime.boot.FastBootEntityManagerFactoryBuilder.build(FastBootEntityManagerFactoryBuilder.java:72)

at io.quarkus.hibernate.orm.runtime.FastBootHibernatePersistenceProvider.createEntityManagerFactory(FastBootHibernatePersistenceProvider.java:71)

at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:80)

at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:55)

at io.quarkus.hibernate.orm.runtime.JPAConfig$LazyPersistenceUnit.get(JPAConfig.java:138)

at io.quarkus.hibernate.orm.runtime.JPAConfig$1.run(JPAConfig.java:54)

at java.base/java.lang.Thread.run(Thread.java:829)

I managed to get connection with the datasource by providing its details as properties in the pom.xml, but now I need to make it read them from the quarkus.properties.

Hopefully this is enough information to understand the situation, but if not, please do let me know and I’ll provide any useful information.

Thanks in advance to anyone who will try to help with it.

Regards,
Dom

2 Likes

Hi. I’m having the same issue.

Did anyone respond? Did you try the example outside of docker?

Thanks in advance.

Josh