keycloak / keycloak-quickstarts

Apache License 2.0
1.99k stars 985 forks source link

Additional persistence unit and datasource, MariaDB #350

Closed lino79 closed 1 year ago

lino79 commented 2 years ago

Describe the bug

I followed this feature: https://github.com/pedroigor/keycloak-quickstarts/tree/issue-10579/user-storage-jpa.

This is my conf/quarkus.properties:

quarkus.datasource."idp".db-kind=mariadb quarkus.datasource."idp".username=root quarkus.datasource."idp".password=**** quarkus.datasource."idp".jdbc.url=jdbc:mariadb://db:3306/idp?characterEncoding=UTF-8

This is my META-INF/persistence.xml (in a JAR dropped in the provider directory):

persistence.txt

Version

18.0.0

Expected behavior

session.getProvider(JpaConnectionProvider.class, "idp") should return a working provider, but returns null.

Actual behavior

I have an error when the application starts:

14 20:44:39,807 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.(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)

How to Reproduce?

No response

Anything else?

No response

nicolabeghin commented 1 year ago

If useful: I got the same error when updating my own extension keycloak-multiple-ds-user-storage to Quarkus - you can find a working example and some indications in the README of the project repo https://github.com/nicolabeghin/keycloak-multiple-ds-user-storage/ and related issue https://github.com/keycloak/keycloak-quickstarts/issues/341 - at least in my case it required to add datasource information both in properties and persistence.xml otherwise they wouldn't be picked up (not optimal but got no other way to get it working)

pedroigor commented 1 year ago

Closing as outdated. Please look at the example here https://github.com/keycloak/keycloak-quickstarts/tree/latest/extension/user-storage-jpa.