Perfect, thanks Dimitry, this is basically what I am doing already. Just
didn't know if I have to close the EntityManager myself, e.g. in the
close() Method.
Greetings
Henning
2018-07-31 5:20 GMT+02:00 Dmitry Telegin <dt(a)acutus.pro>:
Hi Henning,
First, it's recommended that you don't use EntityManager directly in your
RealmResourceProvider, but rather create a facade class to encapsulate JPA
operations.
examples/providers/domain-extension is a nice example of the above (look
for ExampleService and its implementation).
Second, generally you should retrieve an EntityManager before each new
transaction. As long as it's in a local variable, it will be finalized and
closed automatically, so normally you don't need to bother.
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(a)acutus.pro
On Fri, 2018-07-27 at 10:17 +0200, Henning Waack wrote:
> Hi.
>
> I am implementing a RealmResourceProvider (KC 4.0) in which I use an
> EntityManager provided by the KeycloakSession to access the KC DB:
>
> EntityManager em =
> ((KeycloakSession)session).getProvider(JpaConnectionProvider.class).
getEntityManager();
>
> In my class which extends
> org.keycloak.services.resource.RealmResourceProvider and uses this
> EntityManager, do I have to close the EM instance after using it? Or do I
> have to close it in my RealmResourceProviderFactory.close() method
where I
> obtain it from the session?
>
> Thanks & greetings
>
> Henning
> _______________________________________________
> keycloak-user mailing list
> keycloak-user(a)lists.jboss.org
>
https://lists.jboss.org/mailman/listinfo/keycloak-user
--
-----------
Henning Waack | IT Consultant
codecentric AG | Hochstraße 11
<
https://maps.google.com/?q=Hochstra%C3%9Fe+11%C2%A0+%7C+%C2%A0+42697+Soli...
|
<
https://maps.google.com/?q=Hochstra%C3%9Fe+11%C2%A0+%7C+%C2%A0+42697+Soli...
<
https://maps.google.com/?q=Hochstra%C3%9Fe+11%C2%A0+%7C+%C2%A0+42697+Soli...
Solingen
<
https://maps.google.com/?q=Hochstra%C3%9Fe+11%C2%A0+%7C+%C2%A0+42697+Soli...
|Deutschland
<
https://maps.google.com/?q=Hochstra%C3%9Fe+11%C2%A0+%7C+%C2%A0+42697+Soli...
tel: +49 (0)151 108 515 29
www.codecentric.de | blog.codecentric.de |
www.meettheexperts.de
Sitz der Gesellschaft: Solingen | HRB 25917 | Amtsgericht Wuppertal
Vorstand: Michael Hochgürtel . Ulrich Kühn . Rainer Vehns
Aufsichtsrat: Patric Fedlmeier (Vorsitzender) . Klaus Jäger . Jürgen Schütz
Diese E-Mail einschließlich evtl. beigefügter Dateien enthält vertrauliche
und/oder rechtlich geschützte Informationen. Wenn Sie nicht der richtige
Adressat sind oder diese E-Mail irrtümlich erhalten haben, informieren Sie
bitte sofort den Absender und löschen Sie diese E-Mail und evtl.
beigefügter Dateien umgehend. Das unerlaubte Kopieren, Nutzen oder Öffnen
evtl. beigefügter Dateien sowie die unbefugte Weitergabe dieser E-Mail ist
nicht gestattet.