Home Can't inject EntityManager via @PersistenceContext - NullPointerException
 I am trying to create a DataManager, that is used as a facade for my Beans. Unfortunately I can't get the EntityManager to work. I am trying to inject it via @PersistenceContext, but when using the EntityManager I always get a NullPointerException. @ApplicationScoped public class DataManager { @PersistenceContext(unitName = "MSM") private EntityManager em; /* * Adds a new employee to the database. * @param employee - the employee object that will be added. * @return true if transaction was successful. */ public boolean createEmployee(Employee employee){ try { if (employee != null) { if (em.createNamedQuery("Employee.findByMail").setParameter("mail",employee.getMail()).getResultList().isEmpty()) { em.persist(employee); return true; } } } catch (Exception e) { e.printStackTrace(); } return false; } }