1 Reply Latest reply on Oct 5, 2010 2:15 PM by lvdberg

    Is Seam supposed to manage SLSB components injected by @EJB?

    zhangxiubo

      Hi everyone,


      I am facing a problem when building a Seam enabled web application upon a pure EJB module.

      Simply put, I'd like to employ SMPC and manual flushing when the EJBs are used in the web tier while leave them as standard EJBs when accessed by other parts of the system (e.g. MDBs).

      I have some of the EJBs defined as Seam components for web tier use, but as described above I was expecting those beans injected by @EJB to be managed by EJB containers rather than Seam. However, this is not the case:


      @Name("seamEJB")    // This is the EJB the web tier will have access to.
      @Stateless
      public class SeamEJB implements SeamEJBLocal {
      
          @PersistenceContext
          @In    // I am expecting Seam to ignore this when the EJB is injected to other beans using @EJB
          EntityManager entityManager;
      
          public void someMethod(SomeEntity someEntity) {
              ....
          }
      }
      



      // This is a standard EJB used in the back-end only
      @Stateless
      public class ClientEJB impelments ClientEJBLocal, ClientEJBRemote {
          
          @EJB SeamEJBLocal seamEJB;    // Shouldn't seamEJB be managed by EJB container rather than Seam?
                                                (thus entityManager is injected by @PersistenceContext)
      
          public void clientMethod() {
              seamEJB.someMethod(entity);  // This call may cause detached entity exception,
                                                  since SMPC is injected in seamEJB
          }
      }
      


      I think is a fairly logical expectation since I can always inject seamEJB as Seam component using:

      @In SeamEJBLocal seamEJB;


      So my question is:

      Is this behaviour a bug in Seam? If not, then what would be the best way to share Seam components with a pure EJB module without suffering detached entity exceptions/LIEs ?


      Any suggestion is appreciated! Thanks in advance!

        • 1. Re: Is Seam supposed to manage SLSB components injected by @EJB?
          lvdberg

          Hi,


          When you use the name annotation you hand the management of the bean over to seam. For this seam uses its interceptors. I am not 100% sure , but I can imagine that the container is not able to decide which annotation to pick, when Seam is active. Annotations are not intrusive, so when you don't us seam the beans will work as expected.


          Leo