6 Replies Latest reply on Jul 11, 2006 8:19 AM by bambata

    @In vs. @EJB

    bambata

      Hello,

      when I have a stateless service-bean which contains several stateless dao-beans, where is the difference between the two relevant annotations @In and @EJB for injecting the dao.
      Is it correct that @EJB means the EJB-Container manages and injects the dao and that @In means the Seam-framework manages and injects the dao?
      Or if I use @In does Seam recognise the dao as a stateless EJB3.0-Bean and delegates the Injection to the EJB-Container?

      thanks in advance

      hans


        • 1. Re: @In vs. @EJB
          gavin.king

          Right, @In is handled by Seam, and is aware of the Seam names and Seam contexts. For stateless beans there is not really a whole lot of difference between the two. In that case, they are each just sugar over a JNDI lookup. For stateful beans they are very different.

          • 2. Re: @In vs. @EJB
            bambata

            So, in case of a stateless Bean Seam uses for Injection via @In a common
            JNDI-lookup to the containers registry(ENC) ?

            • 3. Re: @In vs. @EJB
              sebasfiorent

               

              "gavin.king@jboss.com" wrote:
              For stateful beans they are very different.


              Gavin, can you explain more precissely which is the difference with stateful beans between @In and @EJB, because I need to choose the correct annotation if they behave different.

              Regards
              Sebastian

              • 4. Re: @In vs. @EJB

                @EJB is EJB injection. For a stateful bean, you will get a new instance created when your other been is created. Think of it as a private instance that Seam knows nothing about - nobody else can inject that instance. For stateful components, you are more likely to want instances to live in a seam-managed context. (converstion, session, whatever) To et that, use @In.

                • 5. Re: @In vs. @EJB
                  gavin.king

                   

                  "bambata" wrote:
                  So, in case of a stateless Bean Seam uses for Injection via @In a common
                  JNDI-lookup to the containers registry(ENC) ?



                  In the case of a SLSB, @In does a JNDI lookup (global or ENC). In the case of a JavaBean, it does a new.

                  • 6. Re: @In vs. @EJB
                    bambata

                    thanks