[keycloak-user] entitymanger is NULL

Daan Zwaenepoel dz at scoutsengidsenvlaanderen.be
Mon Mar 12 08:07:09 EDT 2018


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");
         }
     }



-- 

Met vriendelijke scouts- en gidsengroeten,

<https://www.scoutsengidsenvlaanderen.be> 		*Daan Zwaenepoel | 
Jobstudent - Groepsadministratie* 	 
<https://www.scoutsengidsenvlaanderen.be/het-uitzicht>
*Scouts en Gidsen Vlaanderen vzw*






dz at scoutsengidsenvlaanderen.be <mailto:dz at scoutsengidsenvlaanderen.be>



More information about the keycloak-user mailing list