2 Replies Latest reply on Oct 9, 2005 6:14 AM by Jacek Olszak

    Embedded EJB 3.0 and dependency incjetion

    Jacek Olszak Newbie

      Hi everyone...

      I've created some simply EJB 3 application (1 entity bean, 1 stateless bean) and deployed it as a War in Tomcat. But when I run this code using my client I get the NullPointerException when trying to use EntityManager. I'm injecting EnityManager using @PersistenceContext like this:

      public class JacekDAOBean implements JacekDAO {
       @PersistenceContext(unitName = "custdb")
       protected EntityManager em;
       public JacekDAOBean() {
       em.persist(new Jacek("jacek"));
       * (non-Javadoc)
       * @see entities.JacekDAORemote#getJacek()
       public Jacek getJacek() {
       return (Jacek) em.createQuery("From Jacek j").getSingleResult();

      But the line:
      em.persist(new Jacek("jacek"));

      throws the NullPointerException :(

      Any ideas why ? What I'm doing wrong?

      Thanks in advance