6 Replies Latest reply on Aug 6, 2003 7:23 AM by Adrian Brock

    Dispatch Erro at EJB Lookup ???

    squalidus Newbie

      Hello!

      I am trying to make a simple aplication using JBOSS 3.2.1, Jbulider 7, JDK1.3.1 and Struts.

      The aplication uses the ServiceLocator design Pattern, and, when he try to lookup de EJB Product, a strange error happens...

      The compilation and deploy didnt show any error. Also, the lookup of the Connection Bean works fine...

      Error occurs in this line:
      recurso = initialContext.lookup(nomeJNDI)

      10:04:55,040 ERROR [DispatchAction] Dispatch[/incluirProdutoAction] to method incluirProduto returned an exception
      java.lang.reflect.InvocationTargetException:
      java.lang.StackOverflowError
      at com.sun.naming.internal.VersionHelper12$6.run(VersionHelper12.java:164)
      at java.security.AccessController.doPrivileged(Native Method)
      ...


      I think the error can be in one of xml files:

      *** JBOSS-WEB.XML ***

      <?xml version="1.0" encoding="UTF-8" ?>
      <!DOCTYPE jboss-web (View Source for full doctype...)>
      <jboss-web>
      <ejb-ref>
      <ejb-ref-name>ejb/ControleProduto</ejb-ref-name>
      <jndi-name>java:comp/env/ejb/ControleProduto</jndi-name>
      </ejb-ref>
      </jboss-web>

      *** WEB.XML ***

      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
      <web-app>

      <servlet-name>action</servlet-name>
      <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
      <init-param>
      <param-name>debug</param-name>
      <param-value>2</param-value>
      </init-param>
      <init-param>
      <param-name>application</param-name>
      <param-value>messages.ApplicationResources</param-value>
      </init-param>
      <init-param>
      <param-name>config</param-name>
      <param-value>/WEB-INF/struts-config.xml</param-value>
      </init-param>
      <load-on-startup>2</load-on-startup>

      <servlet-mapping>
      <servlet-name>action</servlet-name>
      <url-pattern>*.do</url-pattern>
      </servlet-mapping>

      <taglib-uri>/WEB-INF/struts-bean.tld</taglib-uri>
      <taglib-location>/WEB-INF/struts-bean.tld</taglib-location>


      <taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>
      <taglib-location>/WEB-INF/struts-html.tld</taglib-location>


      <taglib-uri>/WEB-INF/struts-logic.tld</taglib-uri>
      <taglib-location>/WEB-INF/struts-logic.tld</taglib-location>


      <taglib-uri>/WEB-INF/struts-template.tld</taglib-uri>
      <taglib-location>/WEB-INF/struts-template.tld</taglib-location>


      <ejb-ref>
      <ejb-ref-name>ejb/ControleProduto</ejb-ref-name>
      <ejb-ref-type>Session</ejb-ref-type>
      pdv.casouso.manterproduto.ControleProdutoHome
      pdv.casouso.manterproduto.ControleProduto
      </ejb-ref>
      </web-app>

      *** EJB-JAR.XML ***

      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
      <ejb-jar>
      <enterprise-beans>

      <display-name>ControleProduto</display-name>
      <ejb-name>ControleProduto</ejb-name>
      <local-home>pdv.casouso.manterproduto.ControleProdutoHome</local-home>
      pdv.casouso.manterproduto.ControleProduto
      <ejb-class>pdv.casouso.manterproduto.ControleProdutoBean</ejb-class>
      <session-type>Stateless</session-type>
      <transaction-type>Container</transaction-type>


      <display-name>ControleCompra</display-name>
      <ejb-name>ControleCompra</ejb-name>
      <local-home>pdv.casouso.compraritens.ControleCompraHome</local-home>
      pdv.casouso.compraritens.ControleCompra
      <ejb-class>pdv.casouso.compraritens.ControleCompraBean</ejb-class>
      <session-type>Stateful</session-type>
      <transaction-type>Bean</transaction-type>


      <display-name>ManterFornecedor</display-name>
      <ejb-name>ManterFornecedor</ejb-name>
      pdv.casouso.ManterFornecedor.ManterFornecedorHome
      pdv.casouso.ManterFornecedor.ManterFornecedor
      <local-home>pdv.casouso.ManterFornecedor.ManterFornecedorLocalHome</local-home>
      pdv.casouso.ManterFornecedor.ManterFornecedorLocal
      <ejb-class>pdv.casouso.ManterFornecedor.ManterFornecedorBean</ejb-class>
      <session-type>Stateless</session-type>
      <transaction-type>Container</transaction-type>


      <display-name>Produto</display-name>
      <ejb-name>Produto</ejb-name>
      <local-home>pdv.entidade.produto.ProdutoHome</local-home>
      pdv.entidade.produto.Produto
      <ejb-class>pdv.entidade.produto.ProdutoBean</ejb-class>
      <persistence-type>Container</persistence-type>
      <prim-key-class>java.lang.Long</prim-key-class>
      False
      <cmp-version>2.x</cmp-version>
      <abstract-schema-name>Produto</abstract-schema-name>
      <cmp-field>
      <field-name>codigo</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>nome</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>preco</field-name>
      </cmp-field>
      <primkey-field>codigo</primkey-field>

      <query-method>
      <method-name>findAll</method-name>
      <method-params />
      </query-method>
      <ejb-ql>SELECT DISTINCT OBJECT(p) FROM Produto p</ejb-ql>



      <display-name>Pedido</display-name>
      <ejb-name>Pedido</ejb-name>
      <local-home>pdv.entidade.pedido.PedidoHome</local-home>
      pdv.entidade.pedido.Pedido
      <ejb-class>pdv.entidade.pedido.PedidoBean</ejb-class>
      <persistence-type>Container</persistence-type>
      <prim-key-class>java.lang.Long</prim-key-class>
      False
      <cmp-version>2.x</cmp-version>
      <abstract-schema-name>Pedido</abstract-schema-name>
      <cmp-field>
      <field-name>codigo</field-name>
      </cmp-field>
      <primkey-field>codigo</primkey-field>

      <query-method>
      <method-name>findAll</method-name>
      <method-params />
      </query-method>
      <ejb-ql>SELECT DISTINCT OBJECT(p) FROM Pedido p</ejb-ql>



      <display-name>ItemPedido</display-name>
      <ejb-name>ItemPedido</ejb-name>
      <local-home>pdv.entidade.pedido.ItemPedidoHome</local-home>
      pdv.entidade.pedido.ItemPedido
      <ejb-class>pdv.entidade.pedido.ItemPedidoBean</ejb-class>
      <persistence-type>Container</persistence-type>
      <prim-key-class>java.lang.Long</prim-key-class>
      False
      <cmp-version>2.x</cmp-version>
      <abstract-schema-name>ItemPedido</abstract-schema-name>
      <cmp-field>
      <field-name>oid</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>quantidade</field-name>
      </cmp-field>
      <primkey-field>oid</primkey-field>


      <display-name>Fornecedor</display-name>
      <ejb-name>Fornecedor</ejb-name>
      pdv.entidade.fornecedor.FornecedorRemoteHome
      pdv.entidade.fornecedor.FornecedorRemote
      <local-home>pdv.entidade.fornecedor.FornecedorHome</local-home>
      pdv.entidade.fornecedor.Fornecedor
      <ejb-class>pdv.entidade.fornecedor.FornecedorBean</ejb-class>
      <persistence-type>Container</persistence-type>
      <prim-key-class>java.lang.Long</prim-key-class>
      False
      <cmp-version>2.x</cmp-version>
      <abstract-schema-name>Fornecedor</abstract-schema-name>
      <cmp-field>
      <field-name>razaoSocial</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>oid</field-name>
      </cmp-field>
      <cmp-field>
      <field-name>cnpj</field-name>
      </cmp-field>
      <primkey-field>oid</primkey-field>

      </enterprise-beans>

      <ejb-relation>
      <ejb-relation-name>itemPedido-produto</ejb-relation-name>
      <ejb-relationship-role>
      itemPedido
      <ejb-relationship-role-name>ItemPedidoRelationshipRole</ejb-relationship-role-name>
      Many
      <relationship-role-source>
      itemPedido
      <ejb-name>ItemPedido</ejb-name>
      </relationship-role-source>
      <cmr-field>
      produto
      <cmr-field-name>produto</cmr-field-name>
      </cmr-field>
      </ejb-relationship-role>
      <ejb-relationship-role>
      produto
      <ejb-relationship-role-name>ProdutoRelationshipRole</ejb-relationship-role-name>
      One
      <relationship-role-source>
      produto
      <ejb-name>Produto</ejb-name>
      </relationship-role-source>
      </ejb-relationship-role>
      </ejb-relation>
      <ejb-relation>
      <ejb-relation-name>pedido-itemPedido</ejb-relation-name>
      <ejb-relationship-role>
      pedido
      <ejb-relationship-role-name>PedidoRelationshipRole</ejb-relationship-role-name>
      One
      <relationship-role-source>
      pedido
      <ejb-name>Pedido</ejb-name>
      </relationship-role-source>
      <cmr-field>
      itemPedido
      <cmr-field-name>itensPedido</cmr-field-name>
      <cmr-field-type>java.util.Collection</cmr-field-type>
      </cmr-field>
      </ejb-relationship-role>
      <ejb-relationship-role>
      itemPedido
      <ejb-relationship-role-name>ItemPedidoRelationshipRole</ejb-relationship-role-name>
      Many
      <cascade-delete />
      <relationship-role-source>
      itemPedido
      <ejb-name>ItemPedido</ejb-name>
      </relationship-role-source>
      </ejb-relationship-role>
      </ejb-relation>
      <ejb-relation>
      <ejb-relation-name>fornecedor-produto</ejb-relation-name>
      <ejb-relationship-role>
      fornecedor
      <ejb-relationship-role-name>FornecedorRelationshipRole</ejb-relationship-role-name>
      One
      <relationship-role-source>
      fornecedor
      <ejb-name>Fornecedor</ejb-name>
      </relationship-role-source>
      <cmr-field>
      produto
      <cmr-field-name>produtos</cmr-field-name>
      <cmr-field-type>java.util.Collection</cmr-field-type>
      </cmr-field>
      </ejb-relationship-role>
      <ejb-relationship-role>
      produto
      <ejb-relationship-role-name>ProdutoRelationshipRole</ejb-relationship-role-name>
      Many
      <relationship-role-source>
      produto
      <ejb-name>Produto</ejb-name>
      </relationship-role-source>
      </ejb-relationship-role>
      </ejb-relation>

      <assembly-descriptor>
      <container-transaction>


      <ejb-name>Produto</ejb-name>
      <method-name>*</method-name>

      <trans-attribute>Required</trans-attribute>
      </container-transaction>
      <container-transaction>

      <ejb-name>ControleProduto</ejb-name>
      <method-name>*</method-name>

      <trans-attribute>Required</trans-attribute>
      </container-transaction>
      <container-transaction>

      <ejb-name>Pedido</ejb-name>
      <method-name>*</method-name>

      <trans-attribute>Required</trans-attribute>
      </container-transaction>
      <container-transaction>

      <ejb-name>ItemPedido</ejb-name>
      <method-name>*</method-name>

      <trans-attribute>Required</trans-attribute>
      </container-transaction>
      <container-transaction>

      <ejb-name>Fornecedor</ejb-name>
      <method-name>*</method-name>

      <trans-attribute>Required</trans-attribute>
      </container-transaction>
      <container-transaction>

      <ejb-name>ManterFornecedor</ejb-name>
      <method-name>*</method-name>

      <trans-attribute>Required</trans-attribute>
      </container-transaction>
      </assembly-descriptor>
      </ejb-jar>

      *** JBOSS.XML ***

      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE jboss PUBLIC '-//JBoss//DTD JBOSS 3.0//EN' 'http://www.jboss.org/j2ee/dtd/jboss_3_0.dtd'>


      <enterprise-beans>

      <ejb-name>ControleProduto</ejb-name>
      <local-jndi-name>java:comp/env/ejb/ControleProduto</local-jndi-name>


      <ejb-name>ControleCompra</ejb-name>
      <local-jndi-name>ControleCompra</local-jndi-name>


      <ejb-name>ManterFornecedor</ejb-name>
      <jndi-name>ManterFornecedor</jndi-name>
      <local-jndi-name>ManterFornecedorLocal</local-jndi-name>


      <ejb-name>Produto</ejb-name>
      <local-jndi-name>Produto</local-jndi-name>


      <ejb-name>Pedido</ejb-name>
      <local-jndi-name>Pedido</local-jndi-name>


      <ejb-name>ItemPedido</ejb-name>
      <local-jndi-name>ItemPedido</local-jndi-name>


      <ejb-name>Fornecedor</ejb-name>
      <jndi-name>FornecedorRemote</jndi-name>
      <local-jndi-name>Fornecedor</local-jndi-name>

      </enterprise-beans>


      Anyone have a tip for me ? Im already tried a lot of things... If you need know more about the application,
      tell me how files do you need to see...


      THANKS in ADVANCE

      Squalidus <wirk@hotmail.com>

        • 1. Re: Dispatch Erro at EJB Lookup ???
          Adrian Brock Master

          You have bound the ejb-ref to itself.
          You should be using the global jndi-name rather than
          java:comp/env/etc

          Regards,
          Adrian

          • 2. Re: Dispatch Erro at EJB Lookup ???
            squalidus Newbie

            Thank you very much ! Now, I can understand the
            Stack overflow error... It is in loop.

            But, where is the global jndi-name defined ? At
            JBOSS-WEB.XML or at another xml file ?

            When I try

            nomeJNDI = "ejb/ControleProduto"
            initialContext.lookup(nomeJNDI)

            an "ejb/ControleProduto not bound" error occurs.

            Any more tips ?

            Squalidus

            • 3. Re: Dispatch Erro at EJB Lookup ???
              Adrian Brock Master

              <ejb-ref> is the remote interface
              Since you don't have a <jndi-name> in jboss.xml
              for that bean it will default to <ejb-name>

              Regards,
              Adrian

              • 4. Re: Dispatch Erro at EJB Lookup ???
                squalidus Newbie

                Sorry, but Im really a stupid guy... I tried a lot of things
                but still get the error: Name not Bound !
                (javax.naming.NameNotFoundException: ControleProduto not bound)


                The important parts are listed below. Can you tell me where the
                error is ? Please ?

                Thanks for your patience with me.

                Squalidus

                FILE: ejb-jar.xml
                -----------------


                <display-name>ControleProduto</display-name>
                <ejb-name>ControleProduto</ejb-name>
                <ejb-local-ref>ejb/ControleProduto</ejb-local-ref>
                <local-home>pdv.casouso.manterproduto.ControleProdutoHome</local-home>
                pdv.casouso.manterproduto.ControleProduto
                <ejb-class>pdv.casouso.manterproduto.ControleProdutoBean</ejb-class>
                <session-type>Stateless</session-type>
                <transaction-type>Container</transaction-type>


                FILE: jboss.xml
                ---------------


                <ejb-name>ControleProduto</ejb-name>
                <jndi-name>ejb/ControleProduto</jndi-name>
                <local-jndi-name>java:comp/env/ejb/ControleProduto</local-jndi-name>


                FILE: jboss-web.xml
                -------------------

                <ejb-ref>
                <ejb-ref-name>ControleProduto</ejb-ref-name>
                <jndi-name>ejb/ControleProduto</jndi-name>
                <local-jndi-name>java:comp/env/ejb/ControleProduto</local-jndi-name>
                </ejb-ref>

                FILE: web.xml
                -------------

                <ejb-ref>
                <ejb-ref-name>ControleProduto</ejb-ref-name>
                <ejb-ref-type>Session</ejb-ref-type>
                pdv.casouso.manterproduto.ControleProdutoHome
                pdv.casouso.manterproduto.ControleProduto
                </ejb-ref> Sorry, but Im really a stupid guy... I tried a lot of things
                but still get the error: Name not Bound !
                (javax.naming.NameNotFoundException: ControleProduto not bound)


                The important parts are listed below. Can you tell me where the
                error is ? Please ?

                Thanks for your patience with me.

                FILE: ejb-jar.xml
                -----------------


                <display-name>ControleProduto</display-name>
                <ejb-name>ControleProduto</ejb-name>
                <ejb-local-ref>ejb/ControleProduto</ejb-local-ref>
                <local-home>pdv.casouso.manterproduto.ControleProdutoHome</local-home>
                pdv.casouso.manterproduto.ControleProduto
                <ejb-class>pdv.casouso.manterproduto.ControleProdutoBean</ejb-class>
                <session-type>Stateless</session-type>
                <transaction-type>Container</transaction-type>


                FILE: jboss.xml
                ---------------


                <ejb-name>ControleProduto</ejb-name>
                <jndi-name>ejb/ControleProduto</jndi-name>
                <local-jndi-name>java:comp/env/ejb/ControleProduto</local-jndi-name>


                FILE: jboss-web.xml
                -------------------

                <ejb-ref>
                <ejb-ref-name>ControleProduto</ejb-ref-name>
                <jndi-name>ejb/ControleProduto</jndi-name>
                <local-jndi-name>java:comp/env/ejb/ControleProduto</local-jndi-name>
                </ejb-ref>

                FILE: web.xml
                -------------

                <ejb-ref>
                <ejb-ref-name>ControleProduto</ejb-ref-name>
                <ejb-ref-type>Session</ejb-ref-type>
                pdv.casouso.manterproduto.ControleProdutoHome
                pdv.casouso.manterproduto.ControleProduto
                </ejb-ref>

                • 5. Re: Dispatch Erro at EJB Lookup ???
                  squalidus Newbie

                  Consider only one ! Like I told you, Im a stupid guy.
                  Press CTRL+V twice...

                  Squalidus

                  • 6. Re: Dispatch Erro at EJB Lookup ???
                    Adrian Brock Master

                    You have it very confused.

                    ejb-jar.xml
                    1) You don't define a remote interface
                    2) You have a local reference to itself

                    jboss.xml
                    1) You define a <jndi-name> but there is no remote interface
                    2) You shouldn't define the local jndi binding in java:comp
                    it should go in global jndi. The default binding is
                    local/<ejb-name> if you don't specify it.

                    web.xml
                    1) You specify an ejb-ref which is for the remote
                    interface (you don't have one of these in ejb-jar.xml)

                    jboss-web.xml
                    1) local-jndi-name does not apply to an ejb-ref
                    if you want to reference a local interface, you should
                    use <ejb-local-ref>. Only the very recent jboss-3.2.2RC2
                    supports a <local-jndi-name> to reference a local
                    interface outside the ear. Earlier versions you must
                    use an <ejb-link> in web.xml
                    2) Again, don't reference java:comp here.
                    The java:comp bindings are created by the ejb-refs

                    Regards,
                    Adrian