Reload SPI's on hot deploy (JpaEntityProvider not loaded)

Hi there,

I developed a custom JpaEntityProvider and deployed this as an archive to a running Keycloak instance. The custom entity doesn’t get loaded until I restart the server, because it’s only added to the persistenceUnit upon creation of the EntityManagerFactory, which happens only on boot.

Is there a workaround for this?

Regards

Hot deployment of custom EntityProviders doesn’t work. See https://issues.redhat.com/browse/KEYCLOAK-5782

1 Like

Thanks @xgp. As suggested in the Jira ticket, I solved it by installing the JpaEntityProvider as a module as described in the docs.

In my particular case, I have a separate jar for the JpaEntityProvider only. Because I like hot deploying, I keep my other SPI’s in another jar and deploy them via an ear.

Just leaving this here in case anyone encounters similar problems.

The custom Entities were detected, but not loaded in the persistence unit, resulting in “Not An Entity” exceptions when querying the custom Entities.

Cause: the @Entity annotation was ignored on module load

Solution: add javax.persistance.api and org.hibernate to the module’s dependencies in your module.xml:

<?xml version='1.0' encoding='UTF-8'?>

<module xmlns="urn:jboss:module:1.1" name="my.company.keycloak.jpaentity">

    <resources>
        <resource-root path="spi-providers.jar"/>
    </resources>

    <dependencies>
        <module name="org.keycloak.keycloak-services"/>
        <module name="org.keycloak.keycloak-model-jpa"/>
        <module name="javax.persistence.api"/>
        <module name="org.hibernate"/>
    </dependencies>
</module>

And of course don’t forget to add it in the standalone.xml:

<subsystem xmlns="urn:jboss:domain:keycloak-server:1.1">
    <web-context>auth</web-context>
    <providers>
        <provider>
            module:my.company.keycloak.jpaentity
        </provider>
    </providers>
    ...
1 Like