1 Reply Latest reply on Jul 27, 2007 10:47 AM by Max Rydahl Andersen

    How to lookup EJB 3 session bean from servlet?

    maximuszen Newbie

      I get a NullPointException at the save line.

      public class Test extends HttpServlet {

      private static final long serialVersionUID = -1L;

      @EJB
      private T2Facade t2fl;

      public void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

      T2 t2 = new T2("hello");

      t2fl.save(t2);
      LogUtil.log("t2.getId() = "+t2.getId(),Level.INFO,null);
      LogUtil.log("t2.getX() = "+t2.getX(),Level.INFO,null);
      }


      @Stateless
      public class T2Facade implements T2FacadeLocal {

      @PersistenceContext
      private EntityManager em;

      public void save(T2 t2) {

      // em.persist(t2);
      }


      @Entity
      @SequenceGenerator(name="t2_sequence", sequenceName = "t2_seq")
      public class T2 {

      private static final long serialVersionUID = -2L;


      private Long id;
      private String x;

      public T2(String x) {

      this.x = x;
      }
      @Id
      @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "t2_sequence")
      public Long getId() {
      return id;
      }

      public void setId(Long id) {
      this.id = id;