[keycloak-user] SPI with a third party database. Could not find any META-INF/persistence.xml file in the classpath
Luis Rodríguez Fernández
uo67113 at gmail.com
Thu Nov 22 10:29:34 EST 2018
Hello Dmitry,
Thanks for your prompt response!
I will give it a try and let you know.
Cheers,
Luis
El jue., 22 nov. 2018 a las 11:55, Dmitry Telegin (<dt at acutus.pro>)
escribió:
> Hello Luis,
>
> The path to persistence.xml you've found in the logs is the default
> location of persistence.xml for Keycloak's main module (server-war). But it
> is unused, since Keycloak uses custom persistence.xml location:
>
> https://github.com/keycloak/keycloak/blob/master/model/jpa/src/main/java/org/keycloak/connections/jpa/util/JpaUtils.java#L47
>
> You can use the same method (or at least the same technique) to load yours.
>
> Cheers,
> Dmitry Telegin
> CTO, Acutus s.r.o.
> Keycloak Consulting and Training
>
> Pod lipami street 339/52, 130 00 Prague 3, Czech Republic
> +42 (022) 888-30-71
> E-mail: info at acutus.pro
>
> On Thu, 2018-11-22 at 11:18 +0100, Luis Rodríguez Fernández wrote:
> > Hello there,
> >
> > I am using the standalone server distribution [1].
> >
> > We need to extend the keycloak server [2] and we need to access a third
> > party database to get some data.
> >
> > I developed a sample domain extension based on the keycloak example
> domain
> > extension [3]. The deployment of this example one works at the first try,
> > thanks!!!
> >
> > My sample domain extension access a third party database (mysql), so in
> > wildfly...
> >
> > - I install the mysql driver
> > - I create a datasource
> >
> > ... and in my sample I create a META-INF/persistence.xml
> >
> > <persistence version>
> > <persistence-unit name="JavaHelps" transaction-type="RESOURCE_LOCAL">
> > <non-jta-data-source>java:/MySqlDS</non-jta-data-source>
> > <class>my.entity.Class</class>
> > <properties>
> > <property name="hibernate.dialect"
> > value="org.hibernate.dialect.MySQLDialect"/>
> > </properties>
> > </persistence-unit>
> > </persistence>
> >
> > I add my sample $KEYCLOAK_HOME/bin/jboss-cli.sh --command="module add
> > --name=...
> >
> > And it seems that wildfly likes evrything (from standard output), you can
> > see below part of the wildfly output at startup time. However when I run
> it
> > I get:
> >
> > Uncaught server error: java.lang.ExceptionInInitializerError.... Caused
> by:
> > javax.persistence.PersistenceException: No Persistence provider for
> > EntityManager named JavaHelps
> >
> > I found a workaround: having a deeper look at the standard output I saw
> > this message...
> >
> > parse checking if
> >
> "$KEYCLOAK_HOMEl/modules/system/layers/keycloak/org/keycloak/keycloak-server-subsystem/main/server-war/WEB-INF/classes/META-INF/persistence.xml"
> > exists, result = false
> > 10:59:55,279 TRACE [org.jboss.as.jpa] (MSC service thread 1-1) parsed
> > persistence unit definitions for war server-war
> >
> > ... so if I copy my persistence.xml to that location my domain extension
> > sample WORKS! My question is WHY???
> >
> > Any thoughts on this?
> >
> > Thanks in advance,
> >
> > Luis
> >
> > [1]
> >
> https://downloads.jboss.org/keycloak/4.6.0.Final/keycloak-4.6.0.Final.zip
> > [2]
> >
> https://www.keycloak.org/docs/latest/server_development/index.html#_extensions
> > [3]
> >
> https://github.com/keycloak/keycloak/tree/master/examples/providers/domain-extension
> >
> > 10:59:54,575 INFO [org.jboss.as.connector.subsystems.datasources]
> > (ServerService Thread Pool -- 28) WFLYJCA0005: Deploying
> non-JDBC-compliant
> > driver class com.mysql.jdbc.Driver (version 5.1)
> >
> > 10:59:55,071 INFO [org.jboss.as.connector.subsystems.datasources] (MSC
> > service thread 1-8) WFLYJCA0001: Bound data source [java:/MySqlDS]
> >
> > 10:59:55,158 TRACE [org.jboss.as.jpa] (MSC service thread 1-7) parse
> > checking if
> > "/content/domain-extension-example.jar/META-INF/persistence.xml" exists,
> > result = true
> > 10:59:55,163 TRACE [org.jboss.as.jpa] (MSC service thread 1-7) parse
> > persistence.xml: attribute value(0) = JavaHelps
> > 10:59:55,163 TRACE [org.jboss.as.jpa] (MSC service thread 1-7) parse
> > persistence.xml: attribute value(1) = RESOURCE_LOCAL
> > 10:59:55,164 TRACE [org.jboss.as.jpa] (MSC service thread 1-7) parse
> > persistence.xml: element=non-jta-data-source
> > 10:59:55,164 TRACE [org.jboss.as.jpa] (MSC service thread 1-7) parse
> > persistence.xml: element=class
> > 10:59:55,164 TRACE [org.jboss.as.jpa] (MSC service thread 1-7) parse
> > persistence.xml: element=properties
> > 10:59:55,165 TRACE [org.jboss.as.jpa] (MSC service thread 1-7) parse
> > persistence.xml: reached ending persistence-unit tag
> > 10:59:55,165 INFO [org.jboss.as.jpa] (MSC service thread 1-7)
> WFLYJPA0002:
> > Read persistence.xml for JavaHelps
> > 10:59:55,166 TRACE [org.jboss.as.jpa] (MSC service thread 1-7)
> > PersistenceUnitMetadataImpl(version=2.1) [
> > name: JavaHelps
> > jtaDataSource: null
> > nonJtaDataSource: java:/MySqlDS
> > transactionType: RESOURCE_LOCAL
> > provider: org.hibernate.jpa.HibernatePersistenceProvider
> > classes[
> > com.javahelps.jpa.Student ]
> > packages[
> > ]
> > mappingFiles[
> > ]
> > jarFiles[
> > ]
> > validation-mode: AUTO
> > shared-cache-mode: UNSPECIFIED
> > properties[
> > hibernate.dialect: org.hibernate.dialect.MySQLDialect
> > ]]
> > 10:59:55,167 TRACE [org.jboss.as.jpa] (MSC service thread 1-7) parsed
> > persistence unit definitions for jar domain-extension-example.jar
> > 10:59:55,168 TRACE [org.jboss.as.jpa] (MSC service thread 1-7)
> incrementing
> > PU count for domain-extension-example.jar by 1
> > 10:59:55,174 DEBUG [org.jboss.as.jpa] (MSC service thread 1-3) added
> > javax.persistence.api dependency to domain-extension-example.jar
> > 10:59:55,174 DEBUG [org.jboss.as.jpa] (MSC service thread 1-3) added
> > org.hibernate.bytecodetransformer dependency to
> domain-extension-example.jar
> > 10:59:55,175 DEBUG [org.jboss.as.jpa] (MSC service thread 1-3) added
> > org.jboss.as.jpa dependency to domain-extension-example.jar
> > 10:59:55,175 DEBUG [org.jboss.as.jpa] (MSC service thread 1-3) added
> > org.jboss.as.jpa.spi dependency to domain-extension-example.jar
> > 10:59:55,175 DEBUG [org.jboss.as.jpa] (MSC service thread 1-3) added
> > (default provider) org.hibernate dependency to
> domain-extension-example.jar
> > (since 1 PU(s) didn't specify jboss.as.jpa.providerModule)
> > 10:59:55,175 DEBUG [org.jboss.as.jpa] (MSC service thread 1-3) added
> > org.hibernate dependency to domain-extension-example.jar
> > 10:59:55,196 TRACE [org.jboss.as.jpa] (MSC service thread 1-8) install
> > persistence unit definition for jar domain-extension-example.jar
> > 10:59:55,196 TRACE [org.jboss.as.jpa] (MSC service thread 1-8) adding
> > 'vfs:/content/domain-extension-example.jar/' to annotation index map
> > 10:59:55,196 TRACE [org.jboss.as.jpa] (MSC service thread 1-8) returning
> > global (module) Persistence Provider
> > org.hibernate.jpa.HibernatePersistenceProvider
> > 10:59:55,199 DEBUG [org.jboss.as.jpa] (MSC service thread 1-8) loaded
> > persistence provider adapter
> > org.jboss.as.jpa.hibernate5.HibernatePersistenceProviderAdaptor from
> > classloader ModuleClassLoader for Module "org.hibernate" version
> > 5.3.6.Final from local module loader @400cff1a (finder: local module
> finder
> > @275710fc (roots:
> >
> /media/hdd/keycloak-4.6.0.Final/modules,/media/hdd/keycloak-4.6.0.Final/modules/system/layers/keycloak,/media/hdd/keycloak-4.6.0.Final/modules/system/layers/base))
> > 10:59:55,202 TRACE [org.jboss.as.jpa] (MSC service thread 1-8) add second
> > level cache dependencies with properties '{caches=entity,
> > container=hibernate}'
> > 10:59:55,203 TRACE [org.jboss.as.jpa] (MSC service thread 1-8) added
> > PersistenceUnitService (phase 1 of 2) for 'service
> >
> jboss.persistenceunit."domain-extension-example.jar#JavaHelps".__FIRST_PHASE__'.
> > PU is ready for injector action.
> > 10:59:55,204 TRACE [org.jboss.as.jpa] (MSC service thread 1-8) returning
> > global (module) Persistence Provider
> > org.hibernate.jpa.HibernatePersistenceProvider
> > 10:59:55,206 INFO
> >
> [org.keycloak.subsystem.server.extension.KeycloakProviderDeploymentProcessor]
> > (MSC service thread 1-4) Deploying Keycloak provider:
> > domain-extension-example.jar
> > 10:59:55,234 TRACE [org.jboss.as.jpa] (MSC service thread 1-6) install
> > persistence unit definition for jar domain-extension-example.jar
> > 10:59:55,234 TRACE [org.jboss.as.jpa] (MSC service thread 1-6) adding
> > 'vfs:/content/domain-extension-example.jar/' to annotation index map
> > 10:59:55,234 TRACE [org.jboss.as.jpa] (MSC service thread 1-6) returning
> > global (module) Persistence Provider
> > org.hibernate.jpa.HibernatePersistenceProvider
> > 10:59:55,235 TRACE [org.jboss.as.jpa] (MSC service thread 1-6) add second
> > level cache dependencies with properties '{caches=entity,
> > container=hibernate}'
> > 10:59:55,235 TRACE [org.jboss.as.jpa] (MSC service thread 1-6) added
> > PersistenceUnitService (phase 2 of 2) for 'service
> > jboss.persistenceunit."domain-extension-example.jar#JavaHelps"'. PU is
> > ready for injector action.
> >
> > 10:59:55,645 INFO [org.jboss.as.jpa] (ServerService Thread Pool -- 57)
> > WFLYJPA0010: Starting Persistence Unit (phase 1 of 2) Service
> > 'domain-extension-example.jar#JavaHelps'
> > 10:59:55,695 INFO [org.hibernate.jpa.internal.util.LogHelper]
> > (ServerService Thread Pool -- 57) HHH000204: Processing
> PersistenceUnitInfo
> > [
> > name: JavaHelps
> > ...]
> >
> > 10:59:56,038 INFO [org.jboss.as.jpa] (ServerService Thread Pool -- 57)
> > WFLYJPA0010: Starting Persistence Unit (phase 2 of 2) Service
> > 'domain-extension-example.jar#JavaHelps'
> >
> >
>
--
"Ever tried. Ever failed. No matter. Try Again. Fail again. Fail better."
- Samuel Beckett
More information about the keycloak-user
mailing list