<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hi there,<div class="">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.</div><div class=""><br class=""></div><div class="">In thread I do</div><div class="">KeycloakModelUtils.runJobInTransaction(sessionFactory, new KeycloakSessionTask() {<br class=""> @Override<br class=""> public void run(KeycloakSession session) {</div><div class="">…</div><div class="">EntityManager em = session.getProvider(JpaConnectionProvider.class).getEntityManager();<br class=""></div><div class="">TypedQuery<UserEntity> query = em.createQuery(<br class=""> "select u from UserEntity u where u.realmId = :realmId order by u.username", UserEntity.class);</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">Unfortunately I got java.lang.NoClassDefFoundError: javax/persistence/EntityManager</div><div class=""><br class=""></div><div class=""><br class=""></div><div class="">I tried to set various class loaders via</div><div class="">thread.setContextClassLoader(DefaultJpaConnectionProviderFactory.class.getClassLoader());</div><div class=""><br class=""></div><div class="">but with no success.</div><div class=""><br class=""></div><div class="">I’m running this on EAP 6.4.</div><div class=""><br class=""></div><div class="">What is the proper way how to retrieve entity manager for running custom queries?</div><div class=""><div class="">
<div style="color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class="Apple-interchange-newline">Thanks,</div><div style="color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class=""></div><div style="color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">Libor Krzyžanek</div><div style="color: rgb(0, 0, 0); font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="http://jboss.org" class="">jboss.org</a> Development Team</div>
</div>
<br class=""></div></body></html>