4 Replies Latest reply on Mar 13, 2014 4:33 PM by pgmjsd

    Weld & EJBs (3.1)

    notify

      I have a live SEAM 2.3 project which uses RichFaces and connects to EJBs (3.1) & JPA on the server side running on JBoss AS 6.1. I have been having problems trying to port it to WildFly 8.0 Final and am considering CDI and am looking at Weld as it's included in WildFly/

       

      Does Weld 2.1.2 work with EJBs? Looking in Ken Finningan's book "JBoss Weld CDI for Java Platform" it says:

       

      "A bean type can be a class or interface that is visible to clients that wish to inject it. For instance, an EJB session bean implementation is not visible to clients, but its @local interface is visible"

       

      but then says:-

       

      "EJB remote interfaces are not bean types of a Session Bean, and therefore cannot be injected directly. They must be injected by defining a resource".

       

      In my Seam Application from the Web Page (XHTML) I can directly call an EJB and inject say the selected value from a drop down list, which has been populated previously with the @Factory annotation in my EJB.

       

      Is this all possible in CDI/Weld

       

      TIA

        • 1. Re: Weld & EJBs (3.1)
          mkouba

          Hi Roger,

          I'm not sure I understand your use case completely, but generally yes, it is possible (provided the CDI bean has a bean name declared). However keep in mind that there are significant differences between Seam2 and CDI, e.g. in CDI there's no "bijection".

           

          I'd recommend you to go through the following links:

          1 of 1 people found this helpful
          • 2. Re: Weld & EJBs (3.1)
            notify

            Martin,

             

            Thanks for the comprehensive set of links. Found some of those last night and things are a lot clearer.

            Have printed off your PPT presentation "CDI for Seam 2 developers" which I found very concise & useful.

             

            BTW you say 'in CDI there's no "bijection"' however on slide 7 it says "Core - bijection'.

             

            Is the presentation available as a video from the conference you presented at?

             

            Thanks,

             

            Roger

            • 3. Re: Weld & EJBs (3.1)
              mkouba

              I think it was available but I can't find it right now...

              • 4. Re: Weld & EJBs (3.1)
                pgmjsd

                I've used Seam 2 and CDI.   CDI can definitely recognize EJB3.1 beans as components in pretty much the same way you can with Seam 2.   With EJB3.1 you may not even need to define a local interface, but that may come with some restrictions because the container might not be able to intercept in the same way.

                 

                "EJB remote interfaces are not bean types of a Session Bean, and therefore cannot be injected directly"

                 

                Makes sense / sounds right.  I've never tried to use an @Remote interface for an EJB as a Seam 2 component, but I'd guess that it wouldn't work in CDI or in Seam 2.   I don't think you'd want to do that anyway, because you want your backing beans to be quickly accessible when JSF is rendering your XHTML views.   In the cases where I had to use an EJB remotely, I would define a local EJB (or POJO) component and use that as a wrapper.

                 

                HTH