[keycloak-user] entitymanger is NULL

Marek Posolda mposolda at redhat.com
Tue Mar 13 16:38:36 EDT 2018


Not sure why you use JPA. Are you writing your own userStorage? We have 
an example in our example distribution. It's in directory "providers" . 
I suggest to look there for inspiration and compare why that one works 
and yours doesn't.

Marek

On 12/03/18 13:07, Daan Zwaenepoel wrote:
> Hello everyone
>
> Itry to inject a entitymanger using @PersistenceContext but all that i
> get is a entitymanger that is null anyone who had the same problem?
>
> *file: META-INF/persistence.xml*
>
> <persistence xmlns="http://java.sun.com/xml/ns/persistence"
> <http://java.sun.com/xml/ns/persistence>
>       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> <http://www.w3.org/2001/XMLSchema-instance>
>       xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
> http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
> <http://java.sun.com/xml/ns/persistencehttp://java.sun.com/xml/ns/persistence/persistence_1_0.xsd>
>       version="1.0">
>       <persistence-unit name="groepsadmin" transaction-type="JTA">
>
> <jta-data-source>java:jboss/datasources/GroepsAdminDS</jta-data-source>
> <class>be.scoutsengidsenvlaanderen.login.importer.LidEntity</class>
>
>           <properties>
>               <property name="jboss.as.jpa.managed" value="true"/>
>               <property name="hibernate.show_sql" value="true"/>
>               <property name="hibernate.format_sql" value="true"/>
>               <property name="hibernate.dialect"
> value="org.hibernate.dialect.PostgreSQLDialect"/>
>           </properties>
>       </persistence-unit>
> </persistence>
>
>
> *file: standelone.xml*
>
> <datasource jta="true" jndi-name="java:jboss/datasources/GroepsAdminDS"
> pool-name="GroepsAdminDS" use-java-context="true" use-ccm="true">
> <connection-url>jdbc:postgresql://URL</connection-url>
>           <driver>postgresql</driver>
>           <validation>
>               <check-valid-connection-sql>select
> 1</check-valid-connection-sql>
> <background-validation>true</background-validation>
> <background-validation-millis>10000</background-validation-millis>
>           </validation>
>           <security>
>               <user-name>username</user-name>
>               <password>pass<password>
>           </security>
>       </datasource>
>       <drivers>
>           <driver name="h2" module="com.h2database.h2">
> <xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
>           </driver>
>           <driver name="postgresql" module="org.postgresql">
> <xa-datasource-class>org.postgresql.xa.PGXADataSource</xa-datasource-class>
>           </driver>
>       </drivers>
> </datasources>
>
> *file: class waar ik de entitymanger wil gebruiken*
>
> @Stateless
> public class Leden {
>
>
>       @PersistenceContext(name = "groepsadmin")
>       private EntityManager entityManager;
>
>
>
>
>       public Leden(EntityManager em) {
>           if (entityManager == null){
>               System.out.println("EntityManger is null");
>           }
>       }
>
>
>



More information about the keycloak-user mailing list