@PersistenceContext
works only in managed classes. Your UserDAO
(and UserFacade
) seems to be completely unmanaged and created manually. This way the EntityManager
won't be injected at all. You'd need to manually create it as well. Right now it is null
, which thus explains the NullPointerException
.
Make the UserDAO
(and UserFacade
) a @Stateless
EJB
@Stateless
public class UserDAO {
// ...
}
and use @EJB
to inject them (and remove lazy loading in getter)
@EJB
private UserFacade userFacade; // Also on userDAO.
Or, if your environment doesn't support EJBs (e.g. Tomcat), then you'd need to either upgrade it to TomEE or to install OpenEJB on top of it, or to look for an alternate framework to manage your service facades and DAOs. Spring is often used, but why would you choose for it if Java EE 6 already offers the EJB3 awesomeness?