No, there's no example for this, but you can look at the Keycloak source as we use JPA
ourselves.
You have two options:
a) Shared EntityManager instance with internal Keycloak providers - if you're using
the same db for both this is a good option
b) Separate EntityManager instance
For option a) you should look at extending the default connectionJpa provider to add your
own persistence.xml (you need to copy/modify Keycloak's persistence.xml). Look at
https://github.com/keycloak/keycloak/tree/master/connections/jpa/src/main...
and
https://github.com/keycloak/keycloak/tree/master/model/jpa.
For option b) you can just have your ProviderFactory create the EntityManagerFactory and
pass it to the Provider instance. For this you only need to look at
https://github.com/keycloak/keycloak/tree/master/connections/jpa/src/main....
----- Original Message -----
From: "Alexander Chriztopher"
<alexander.chriztopher(a)gmail.com>
To: "Stian Thorgersen" <stian(a)redhat.com>
Cc: keycloak-user(a)lists.jboss.org
Sent: Friday, 28 November, 2014 11:01:46 AM
Subject: Re: [keycloak-user] Providers with CDI
ok ! Are there any examples of using JPA ?
On Fri, Nov 28, 2014 at 10:54 AM, Stian Thorgersen <stian(a)redhat.com> wrote:
> No, afraid we don't support CDI (or any other managed features such as
> EJBs) in our providers. They are just POJO's and Keycloak manages their
> life-cycle.
>
> In the future we may make it simpler to create providers, but this is not
> a priority atm.
>
> ----- Original Message -----
> > From: "Alexander Chriztopher"
<alexander.chriztopher(a)gmail.com>
> > To: keycloak-user(a)lists.jboss.org
> > Sent: Friday, 28 November, 2014 10:14:32 AM
> > Subject: [keycloak-user] Providers with CDI
> >
> > Hi All,
> >
> > I there a way to get providers to be managed by CDI.
> >
> > The aim is to get access to services such as entity manager injection and
> > lifecycle management which would be done manually today.
> >
> > Thanks for any help.
> >
> > _______________________________________________
> > keycloak-user mailing list
> > keycloak-user(a)lists.jboss.org
> >
https://lists.jboss.org/mailman/listinfo/keycloak-user
>