<div dir="ltr">It&#39;s not very easy to get Persistence to pick-up the persistence.xml file from a module. We&#39;ve got a fix for this coming in 1.9.2, but you can just copy/paste the lines from <a href="https://github.com/keycloak/keycloak/blob/master/model/jpa/src/main/java/org/keycloak/connections/jpa/util/JpaUtils.java#L43">https://github.com/keycloak/keycloak/blob/master/model/jpa/src/main/java/org/keycloak/connections/jpa/util/JpaUtils.java#L43</a>. It uses Hibernate classes directly to create the EntityManagerFactory which allows specifying the classloader. Just use the classloader for your <span style="font-size:12.8px">UserFederationProviderFactory implementation.</span></div><div class="gmail_extra"><br><div class="gmail_quote">On 6 April 2016 at 05:12, Anthony Fryer <span dir="ltr">&lt;<a href="mailto:Anthony.Fryer@virginaustralia.com" target="_blank">Anthony.Fryer@virginaustralia.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">





<div lang="EN-AU" link="blue" vlink="purple">
<div>
<p class="MsoNormal">Hi All,<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">I’m implementing a UserFederationProviderFactory and want to create an EntityManagerFactory from one of its methods.  I have packaged up a persistence.xml in the META-INF folder of the SPI jar file and deployed this as a module to the keycloak
 standalone server.  <u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">My module.xml looks like this…<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">&lt;module xmlns=&quot;urn:jboss:module:1.3&quot; name=&quot;acme.keycloak-acme-user-federation&quot;&gt;<u></u><u></u></p>
<p class="MsoNormal">    &lt;resources&gt;<u></u><u></u></p>
<p class="MsoNormal">        &lt;resource-root path=&quot;keycloak-acme-user-federation-1.0.0.jar&quot;&gt;<u></u><u></u></p>
<p class="MsoNormal">            &lt;filter&gt;<u></u><u></u></p>
<p class="MsoNormal">                &lt;include path=&quot;META-INF/**&quot;/&gt;<u></u><u></u></p>
<p class="MsoNormal">            &lt;/filter&gt;<u></u><u></u></p>
<p class="MsoNormal">        &lt;/resource-root&gt;<u></u><u></u></p>
<p class="MsoNormal">    &lt;/resources&gt;<u></u><u></u></p>
<p class="MsoNormal">    &lt;dependencies&gt;<u></u><u></u></p>
<p class="MsoNormal">        &lt;module name=&quot;org.keycloak.keycloak-core&quot;/&gt;<u></u><u></u></p>
<p class="MsoNormal">        &lt;module name=&quot;org.keycloak.keycloak-server-spi&quot;/&gt;<u></u><u></u></p>
<p class="MsoNormal">        &lt;module name=&quot;javax.api&quot;/&gt;<u></u><u></u></p>
<p class="MsoNormal">        &lt;module name=&quot;javaee.api&quot;/&gt;<u></u><u></u></p>
<p class="MsoNormal">        &lt;module name=&quot;org.hibernate&quot; /&gt;<u></u><u></u></p>
<p class="MsoNormal">        &lt;module name=&quot;org.jboss.ws.cxf.jbossws-cxf-client&quot;/&gt;<u></u><u></u></p>
<p class="MsoNormal">    &lt;/dependencies&gt;<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">&lt;/module&gt;<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">In my UserFederationProviderFactory I have a method like this…<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">                private EntityManagerFactory getEntityManagerFactory(UserFederationProviderModel model) {<u></u><u></u></p>
<p class="MsoNormal">                                if (emf == null) {<u></u><u></u></p>
<p class="MsoNormal">                                                logger.trace(&quot;Creating entityManagerFactory...&quot;);<u></u><u></u></p>
<p class="MsoNormal">                                                Map&lt;String, String&gt; config = model.getConfig();<u></u><u></u></p>
<p class="MsoNormal">                                                Properties p = new Properties();<u></u><u></u></p>
<p class="MsoNormal">                                                // for now just use hibernate built in connection factory<u></u><u></u></p>
<p class="MsoNormal">                                                p.put(&quot;hibernate.connection.driver_class&quot;, config.get(DATABASE_DRIVER_CLASS_NAME));<u></u><u></u></p>
<p class="MsoNormal">                                                p.put(&quot;hibernate.connection.url&quot;, config.get(DATABASE_URL));<u></u><u></u></p>
<p class="MsoNormal">                                                p.put(&quot;hibernate.connection.username&quot;, config.get(DATABASE_USER));<u></u><u></u></p>
<p class="MsoNormal">                                                p.put(&quot;hibernate.connection.password&quot;, config.get(DATABASE_PASSWORD));<u></u><u></u></p>
<p class="MsoNormal">                                                p.put(&quot;hibernate.show_sql&quot;, &quot;true&quot;);<u></u><u></u></p>
<p class="MsoNormal">                                                p.put(&quot;hibernate.format_sql&quot;, &quot;true&quot;);<u></u><u></u></p>
<p class="MsoNormal">                                                emf = Persistence.createEntityManagerFactory(&quot;acmeEntities&quot;, p);<u></u><u></u></p>
<p class="MsoNormal">                                }<u></u><u></u></p>
<p class="MsoNormal">                                <u></u><u></u></p>
<p class="MsoNormal">                                return emf;<u></u><u></u></p>
<p class="MsoNormal">                }<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">When this method is called, it always returns the error “No Persistence provider for EntityManager named acmeEntities”.<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">I’m 90% sure this is to do with the ClassLoader being used by Persistence not being able to see the META-INF/persistence.xml packaged up in the keycloak-acme-user-federation-1.0.0.jar.  Does anyone have an idea what I need to do to my module
 configuration to get this working?<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Thanks,<u></u><u></u></p>
<p class="MsoNormal"><u></u> <u></u></p>
<p class="MsoNormal">Anthony Fryer<u></u><u></u></p>
<p class="MsoNormal"><span><u></u> <u></u></span></p>
<p class="MsoNormal"><u></u> <u></u></p>
</div>
The content of this e-mail, including any attachments, is a confidential communication between Virgin Australia Airlines Pty Ltd (Virgin Australia) or its related entities (or the sender if this email is a private communication) and the intended addressee and
 is for the sole use of that intended addressee. If you are not the intended addressee, any use, interference with, disclosure or copying of this material is unauthorized and prohibited. If you have received this e-mail in error please contact the sender immediately
 and then delete the message and any attachment(s). There is no warranty that this email is error, virus or defect free. This email is also subject to copyright. No part of it should be reproduced, adapted or communicated without the written consent of the
 copyright owner. If this is a private communication it does not represent the views of Virgin Australia or its related entities. Please be aware that the contents of any emails sent to or from Virgin Australia or its related entities may be periodically monitored
 and reviewed. Virgin Australia and its related entities respect your privacy. Our privacy policy can be accessed from our website: <a href="http://www.virginaustralia.com" target="_blank">www.virginaustralia.com</a>
</div>

<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" rel="noreferrer" target="_blank">https://lists.jboss.org/mailman/listinfo/keycloak-user</a><br></blockquote></div><br></div>