<div dir="ltr">thank you Stian.<div><br></div><div>I have found my error. I was using a JTA transaction provider and changed that to a local one and it is now working.</div><div><br></div><div>Just in case anyone is interested this is how my persistence.xml is :</div><div><br></div><div><div><?xml version="1.0" encoding="UTF-8"?></div><div><persistence version="2.1" xmlns="<a href="http://xmlns.jcp.org/xml/ns/persistence">http://xmlns.jcp.org/xml/ns/persistence</a>" xmlns:xsi="<a href="http://www.w3.org/2001/XMLSchema-instance">http://www.w3.org/2001/XMLSchema-instance</a>"</div><div><span class="" style="white-space:pre">        </span>xsi:schemaLocation="<a href="http://xmlns.jcp.org/xml/ns/persistence">http://xmlns.jcp.org/xml/ns/persistence</a> <a href="http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd</a>"></div><div><span class="" style="white-space:pre">        </span><persistence-unit name="security" transaction-type="RESOURCE_LOCAL"></div><div><span class="" style="white-space:pre">                </span><jta-data-source>java:jboss/datasources/security</jta-data-source></div><div><span class="" style="white-space:pre">                </span><properties><br></div><div><span class="" style="white-space:pre">                        </span><property name="hibernate.hbm2ddl.auto" value="validate" /></div><div><span class="" style="white-space:pre">                        </span><property name="hibernate.show_sql" value="true" /></div><div><span class="" style="white-space:pre">                        </span><property name="hibernate.format_sql" value="true" /></div><div> <!-- Set jboss.as.jpa.managed to false to disable container managed JPA access to the persistence unit --></div><div> <property name="jboss.as.jpa.managed" value="false"/></div><div><span class="" style="white-space:pre">                </span></properties><br></div><div><span class="" style="white-space:pre">        </span></persistence-unit></div><div></persistence></div></div><div><br></div><div>And this how i create my entity manager to handle the transaction :</div><div><br></div><div><div>EntityManagerFactory emf = Persistence.createEntityManagerFactory("security");</div><div>EntityManager em = emf.createEntityManager();</div></div><div>em.getTransaction().begin();<br></div><div>// some code to save data to the db</div><div>em.getTransaction().commit();<br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Nov 28, 2014 at 11:10 AM, Stian Thorgersen <span dir="ltr"><<a href="mailto:stian@redhat.com" target="_blank">stian@redhat.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">No, there's no example for this, but you can look at the Keycloak source as we use JPA ourselves.<br>
<br>
You have two options:<br>
<br>
a) Shared EntityManager instance with internal Keycloak providers - if you're using the same db for both this is a good option<br>
b) Separate EntityManager instance<br>
<br>
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 <a href="https://github.com/keycloak/keycloak/tree/master/connections/jpa/src/main/java/org/keycloak/connections/jpa" target="_blank">https://github.com/keycloak/keycloak/tree/master/connections/jpa/src/main/java/org/keycloak/connections/jpa</a> and <a href="https://github.com/keycloak/keycloak/tree/master/model/jpa" target="_blank">https://github.com/keycloak/keycloak/tree/master/model/jpa</a>.<br>
<br>
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 <a href="https://github.com/keycloak/keycloak/tree/master/connections/jpa/src/main/java/org/keycloak/connections/jpa" target="_blank">https://github.com/keycloak/keycloak/tree/master/connections/jpa/src/main/java/org/keycloak/connections/jpa</a>.<br>
<span class="im HOEnZb"><br>
----- Original Message -----<br>
> From: "Alexander Chriztopher" <<a href="mailto:alexander.chriztopher@gmail.com">alexander.chriztopher@gmail.com</a>><br>
</span><div class="HOEnZb"><div class="h5">> To: "Stian Thorgersen" <<a href="mailto:stian@redhat.com">stian@redhat.com</a>><br>
> Cc: <a href="mailto:keycloak-user@lists.jboss.org">keycloak-user@lists.jboss.org</a><br>
> Sent: Friday, 28 November, 2014 11:01:46 AM<br>
> Subject: Re: [keycloak-user] Providers with CDI<br>
><br>
> ok ! Are there any examples of using JPA ?<br>
><br>
> On Fri, Nov 28, 2014 at 10:54 AM, Stian Thorgersen <<a href="mailto:stian@redhat.com">stian@redhat.com</a>> wrote:<br>
><br>
> > No, afraid we don't support CDI (or any other managed features such as<br>
> > EJBs) in our providers. They are just POJO's and Keycloak manages their<br>
> > life-cycle.<br>
> ><br>
> > In the future we may make it simpler to create providers, but this is not<br>
> > a priority atm.<br>
> ><br>
> > ----- Original Message -----<br>
> > > From: "Alexander Chriztopher" <<a href="mailto:alexander.chriztopher@gmail.com">alexander.chriztopher@gmail.com</a>><br>
> > > To: <a href="mailto:keycloak-user@lists.jboss.org">keycloak-user@lists.jboss.org</a><br>
> > > Sent: Friday, 28 November, 2014 10:14:32 AM<br>
> > > Subject: [keycloak-user] Providers with CDI<br>
> > ><br>
> > > Hi All,<br>
> > ><br>
> > > I there a way to get providers to be managed by CDI.<br>
> > ><br>
> > > The aim is to get access to services such as entity manager injection and<br>
> > > lifecycle management which would be done manually today.<br>
> > ><br>
> > > Thanks for any help.<br>
> > ><br>
> > > _______________________________________________<br>
> > > keycloak-user mailing list<br>
> > > <a href="mailto:keycloak-user@lists.jboss.org">keycloak-user@lists.jboss.org</a><br>
> > > <a href="https://lists.jboss.org/mailman/listinfo/keycloak-user" target="_blank">https://lists.jboss.org/mailman/listinfo/keycloak-user</a><br>
> ><br>
><br>
</div></div></blockquote></div><br></div>