12 Replies Latest reply on Nov 13, 2007 8:12 AM by pmuir

    Using an EJB3 in seam

    german.castro

      I have 3 projects in RH studio:
      - A seam project
      - An ejb project
      - ear project that contains the others.

      I need call an ejb from seam project but when i do the jndi lookup it returns a null pointer.

      I use:

      @EJB TheBeanLocal bean

      and

      bean = (TheBeanLocal)ctx.lookup("project/TheBean/local");

      The lookup don't fails, but in both cases 'bean' is null.

      What could be wrong?

        • 1. Re: Using an EJB3 in seam
          pmuir

          Ok, but whats the deployed structure of your project?

          • 2. Re: Using an EJB3 in seam
            german.castro

            The way of use an ejb or resources is the same of other kind of projects??

            I also was trying to use a datasource from a seam action and this returns null (ds is null):

            @Resource (mappedName="jndi") DataSource ds;


            The deploy structure is this:

            ClientPortal.ear
            |-- ClientPortalWeb.war
            | |-- META-INF
            | | `-- MANIFEST.MF
            | |-- WEB-INF
            | | |-- classes
            | | | |-- ClientPortalWeb-ds.xml
            | | | |-- META-INF
            | | | | `-- persistence.xml
            | | | |-- ..... actions
            | | | |-- components.properties
            | | | |-- import.sql
            | | | |-- messages_en.properties
            | | | |-- seam.properties
            | | | `-- security.drl
            | | |-- components.xml
            | | |-- faces-config.xml
            | | |-- jboss-web.xml
            | | |-- lib
            | | | |-- jboss-seam-debug.jar
            | | | |-- jboss-seam-ui.jar
            | | | |-- jsf-facelets.jar
            | | | |-- richfaces-impl.jar
            | | | `-- richfaces-ui.jar
            | | |-- pages.xml
            | | `-- web.xml
            | |-- error.xhtml
            | |-- home.xhtml
            | |-- img
            | | |-- cal-next.png
            | | |-- cal-prev.png
            | | |-- dtpick.gif
            | |-- index.html
            | |-- layout
            | | |-- display.xhtml
            | | |-- edit.xhtml
            | | |-- loginout.xhtml
            | | |-- menu.xhtml
            | | `-- template.xhtml
            | |-- login.page.xml
            | |-- login.xhtml
            | |-- stylesheet
            | | `-- theme.css
            |-- META-INF
            | |-- MANIFEST.MF
            | `-- application.xml
            |-- jboss-seam.jar
            |-- lib
            | |-- antlr-runtime.jar
            | |-- commons-beanutils.jar
            | |-- commons-digester.jar
            | |-- drools-compiler.jar
            | |-- drools-core.jar
            | |-- ejb-api.jar
            | |-- el-api.jar
            | |-- janino.jar
            | |-- jboss-el.jar
            | |-- jboss-seam-gen.jar
            | |-- jboss-seam-ioc.jar
            | |-- jboss-seam-mail.jar
            | |-- jboss-seam-pdf.jar
            | |-- jboss-seam-remoting.jar
            | |-- jbpm-jpdl.jar
            | |-- jsf-api.jar
            | |-- jsf-impl.jar
            | |-- mvel14.jar
            | `-- richfaces-api.jar
            `-- servicesClientPortal.jar
            |-- META-INF
            | |-- MANIFEST.MF
            | `-- ejb-jar.xml
            `-- cl
            `-- ..... ejbs

            • 3. Re: Using an EJB3 in seam
              arussel

              if you're using jboss, you can have a look in jmx-console or web console to see what is in the JNDI.
              Can you see what you're looking for ?
              alex

              • 4. Re: Using an EJB3 in seam
                german.castro

                Yes i can see the jndi.

                If i use a wrong name i got an exception, but this only returns a null resource, without exception.

                • 5. Re: Using an EJB3 in seam
                  german.castro

                  Mmmm... seem to be that isn't finding any jndi...

                  could be related with this message?

                  INFO [SessionFactoryObjectFactory] Not binding factory to JNDI, no JNDI name configured

                  How i fix it?

                  • 6. Re: Using an EJB3 in seam
                    pmuir

                    So where does the Seam project appear in that structure.

                    • 7. Re: Using an EJB3 in seam
                      german.castro

                      The seam project is the ClientProjectWeb.war

                      • 8. Re: Using an EJB3 in seam
                        pmuir

                        That certainly should work.

                        • 9. Re: Using an EJB3 in seam
                          german.castro


                          Well after many hours :( i found in documentation that a EJB must be called using the annotation @Name("name") and Component.getInstance("name") and not using a jndi lookup ...

                          newbie mistake...

                          But what happends if i have an EJB from other application (not seam) that isn't seam aware? I have been many time trying to call ejb seam awareness and don't works.

                          • 10. Re: Using an EJB3 in seam
                            pmuir

                            No, thats how you lookup a Seam component. Ask about looking up EJBs in the EJB forum ;)

                            • 11. Re: Using an EJB3 in seam
                              german.castro

                              Mmm... but something is wrong in the seam conf, because if i add a webservice in the archive .jar that contains the EJBs, this works fine. But any call to jndi (@Resource or @EJB) from a 'seam action' in archive .war don't works.

                              Exist an example that call an EJB from seam? in the examples i only saw calls EJB like seam components.

                              • 12. Re: Using an EJB3 in seam
                                pmuir

                                Seam doesn't alter EJB3 lookups in any way.

                                We don't have an example in the Seam distro which does this.