3 Replies Latest reply on Sep 9, 2005 7:27 AM by epbernard

    Does @EJB only work in session beans?

    pabry

      Why can't I use @EJB in Entity beans or in plain classes?
      /Patrik

        • 1. Re: Does @EJB only work in session beans?
          epbernard

          When/how should I inject stuffs in a POJO

          MyPojo pojo = new MyPojo();
          pojo = null;


          • 2. Re: Does @EJB only work in session beans?
            pabry

            Suppose that I have a session bean called SessionA and an entity bean called EntityA. SessionA have methods that operate on EntityA.

            Also suppose that I have another session bean called SessionB and an entity bean called EntityB. SessionB have methods that operate on EntityB.

            Now, if EntityA wants to operate on some EntityB objects (that isn't part of it's attributes) it must go via SessionB.

            BUT EntityA can inject a dependency to SessionB via @EJB. I get a null pointer when I try to use the SessionB reference.

            So my question remains: Why doesn't @EJB in entity beans (and in POJOs).

            /Patrik

            • 3. Re: Does @EJB only work in session beans?
              epbernard

              This is a very bad design. Your domain model (aka entity model) shouldn't call/use any kind of service (either entitymanager or EJB session or any kind of process layer).