thank you Stian.
I have found my error. I was using a JTA transaction provider and changed
that to a local one and it is now working.
Just in case anyone is interested this is how my persistence.xml is :
<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.1"
<persistence-unit name="security"
transaction-type="RESOURCE_LOCAL">
<jta-data-source>java:jboss/datasources/security</jta-data-source>
<properties>
<property name="hibernate.hbm2ddl.auto" value="validate" />
<property name="hibernate.show_sql" value="true" />
<property name="hibernate.format_sql" value="true" />
<!-- Set jboss.as.jpa.managed to false to disable container
managed JPA access to the persistence unit -->
<property name="jboss.as.jpa.managed"
value="false"/>
</properties>
</persistence-unit>
</persistence>
And this how i create my entity manager to handle the transaction :
EntityManagerFactory emf =
Persistence.createEntityManagerFactory("security");
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
// some code to save data to the db
em.getTransaction().commit();
On Fri, Nov 28, 2014 at 11:10 AM, Stian Thorgersen <stian(a)redhat.com> wrote:
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
> >
>