[keycloak-user] How to access entity manager from custom thread

Tristan Paddock tristan.paddock at gmail.com
Mon Aug 24 15:01:30 EDT 2015


It looks like Keycloak 1.2 supports JBoss Modules. Try creating a module
add specifically add 'javax.persistence.api' and see if that helps.

Tristan

On Mon, Aug 24, 2015 at 2:27 PM, Libor Krzyžanek <lkrzyzan at redhat.com>
wrote:

> Hi,
> it’s a jar in providers folder.
>
> Does Keycloak 1.2 allows custom providers as a module?
>
> Thanks,
>
> Libor Krzyžanek
> jboss.org Development Team
>
> On 24 Aug 2015, at 17:09, Tristan Paddock <tristan.paddock at gmail.com>
> wrote:
>
> How are you including your jar file? Is it located under
> 'standalone/configuration/providers'? Or did you create a module? If you
> created a module be sure to include 'javax.persistence.api' as a
> dependency. That was an issue I ran into, making sure I included the
> correct dependencies for my module.
>
> Tristan
>
> On Mon, Aug 24, 2015 at 10:33 AM, Libor Krzyžanek <lkrzyzan at redhat.com>
> wrote:
>
>> Hi there,
>> within my listener factory's postInit method I’m creating a separate
>> thread that needs to run a sql query by using entity manager from JPA
>> provider.
>>
>> In thread I do
>> KeycloakModelUtils.runJobInTransaction(sessionFactory,
>> new KeycloakSessionTask() {
>>    @Override
>>    public void run(KeycloakSession session) {
>>>> EntityManager em =
>> session.getProvider(JpaConnectionProvider.class).getEntityManager();
>> TypedQuery<UserEntity> query = em.createQuery(
>>       "select u from UserEntity u where u.realmId = :realmId order by
>> u.username", UserEntity.class);
>>
>>
>> Unfortunately I got java.lang.NoClassDefFoundError:
>> javax/persistence/EntityManager
>>
>>
>> I tried to set various class loaders via
>>
>> thread.setContextClassLoader(DefaultJpaConnectionProviderFactory.class.getClassLoader());
>>
>> but with no success.
>>
>> I’m running this on EAP 6.4.
>>
>> What is the proper way how to retrieve entity manager for running custom
>> queries?
>>
>> Thanks,
>>
>> Libor Krzyžanek
>> jboss.org Development Team
>>
>>
>> _______________________________________________
>> keycloak-user mailing list
>> keycloak-user at lists.jboss.org
>> https://lists.jboss.org/mailman/listinfo/keycloak-user
>>
>
>
>
>


-- 
Tristan Paddock

Tristan.Paddock at gmail.com
970.901.9400
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/keycloak-user/attachments/20150824/5bf0d24f/attachment.html 


More information about the keycloak-user mailing list