6 Replies Latest reply on Apr 10, 2002 12:16 PM by cs

    Using local references from session bean to entity bean?

    Jonas Bergqvist Newbie

      Hi all!

      I have done some searches here in the forum and elsewhere. It seems that there is some problems using ejb-local-ref in jboss.

      I have an architecture with some Session Facades (session beans) which interacts with one or more entity beans. When using the remote references (ejb-ref in the dd) everything works fine. But I just can't seem to get it to work with local interfaces (ejb-local-ref). Doesn't Jboss 2.4.4 support this feature?

      Is it possible to put a ejb-local-ref in the jboss vendor dd at all? The (new, commercial) documentation most correctly states that the ejb-jar.xml file supports this tag, but it doesn't mention this tag for its own dd (jboss.xml). If this is the case it kinda sucks, I must say. They could at least have mentioned this explicitly then.

      But what I am interested in is, of course, the possibility that I am wrong (I surely hope so). Has anyone of you succesfully used the ejb-local-ref between ejb:s?

      Regards,

      Jonas

      PS. Some more detail:
      -Version: JBoss-2.4.4_Tomcat-4.0.1
      -I have successfully used local interfaces, per se, when accessing the beans through them directly from a client.

        • 1. Re: Using local references from session bean to entity bean?
          Andreas Schouten Newbie

          Local references are defined in ejb-jar.xml and not in a jboss descriptor.

          Example:

          <ejb-jar>
          <enterprise-beans>

          <ejb-local-ref>
          <local-home>eacm.ejb.RolesHome</local-home>
          eacm.ejb.Roles
          <ejb-ref-type>Entity</ejb-ref-type>
          <ejb-ref-name>RolesEntity</ejb-ref-name>
          <ejb-link>RolesEJB</ejb-link>
          </ejb-local-ref>
          ....

          ejb-link is mandatory in jBoss 2.4.4 while it isn't in the ejb spec.

          hth
          Andreas

          • 2. Re: Using local references from session bean to entity bean?
            Jonas Bergqvist Newbie

            Thanks for your reply, Andreas! I gather you have gotten it to work.

            I know I have to define the local reference in the ejb-jar.xml file and I have done so. But when I try to look up the local bean jboss tells me that its name is not bound. It works well if the reference is not local:

            ::From ejb-jar.xml (remote ref)
            ...
            <ejb-name>CaseManagerBean</ejb-name>
            <ejb-ref>
            <ejb-ref-name>ejb/CaseBean</ejb-ref-name>
            <ejb-ref-type>Entity</ejb-ref-type>
            acompany.CaseHome
            acompany.Case
            <ejb-link>CaseBean</ejb-link>
            </ejb-ref>
            ...
            ::From jboss.xml (remote ref)

            ...
            <ejb-name>CaseManagerBean</ejb-name>
            <ejb-ref>
            <ejb-ref-name>ejb/CaseBean</ejb-ref-name>
            <jndi-name>ejb/cases/Case</jndi-name>
            </ejb-ref>
            ...
            This lookup works good for the remote ejb-ref above:
            ctx.lookup("java:comp/env/ejb/CaseBean");

            -----------------

            ::Same but with LOCAL ref, ejb-jar.xml:
            (same as above, but:)
            <ejb-local-ref>
            <ejb-ref-name>ejb/CaseBeanLocal</ejb-ref-name>
            <ejb-ref-type>Entity</ejb-ref-type>
            <local-home>acompany.CaseLocalHome</local-home>
            acompany.CaseLocal
            <ejb-link>CaseBean</ejb-link>
            </ejb-local-ref>

            Am I now to put an ejb-LOCAL-ref tag in the jboss.xml? The jboss DTD does not seem to support this tag (at least not according to their manual)...

            What does your jboss.xml look like for the bean you describe in your reply?

            Regards,

            Jonas



            • 3. Re: Using local references from session bean to entity bean?
              cs Newbie

              hi andreas,
              i am not able to look an entity bean from a session bean.iam getting the following error.

              Exception:java.rmi.ServerException: RemoteException occurred in server thread; nested exception is:
              java.rmi.ServerException: Transaction rolled back; nested exception is:
              java.lang.NullPointerException

              if u have any example code of one bean looking another with local-ref ,please post it here with code and ejb-jar.xml.
              it would be helpful .

              Thanks

              • 4. Re: Using local references from session bean to entity bean?
                Andreas Schouten Newbie

                Hi,

                you can get a list of all bound jndi names.

                open http://yourserver:8082
                and chose the link:

                service=JNDIView

                You'll see a botton 'list' and get somethig like this:

                java:comp namespace of the DataInterface bean:
                +- env (class: org.jnp.interfaces.NamingContext)
                | +- RiskCurveEntity (class: eacm.ejb.RiskCurveHome)
                | +- PersonEntity (class: eacm.ejb.PersonHome)
                | +- RolesEntity (class: eacm.ejb.RolesHome)
                .....
                | +- CodedValueListStringEntry (class: eacm.ejb.CodedValueListEntryHome)
                | +- ejb (class: org.jnp.interfaces.NamingContext)
                | | +- CodedValueListEJBMVCLocal (class: eacm.rule.CodedValueListHome)
                | | +- VolaEJBMVCLocal (class: eacm.ejb.VolaHome)
                | | +- MarketDataInputEJBMVCLocal (class:
                ....

                In my first example I defined the
                <ejb-ref-name>RolesEntity</ejb-ref-name>

                From the context of session bean 'DataInterface' now I can lookup:

                Context initial = getContext();
                RoleHome= (RoleHome) initial.lookup("java:comp/env/RoleEntity");

                You should be able to lookup
                java:comp/env/ejb/CaseBean

                Andreas

                • 5. Re: Using local references from session bean to entity bean?
                  Jonas Bergqvist Newbie

                  As always I seem to solve problems just after having asked a question about them... well, well.

                  The only thing I had to do was NOT to have an ejb-ref in the jboss.xml if I just had an ejb-LOCAL-ref in ejb-jar.xml. This seems a bit weird but there is probably some good reason for it I guess. What got me going in the wrong direction is that you HAVE to specify an ejb-ref in the jboss.xml if you have a REMOTE ejb-ref in your ejb-jar.xml. Well, now everything is working nice and smooth.

                  So you did answer my question Andreas. Thanks!

                  .jonas

                  • 6. Re: Using local references from session bean to entity bean?
                    cs Newbie

                    hi jonas and andreas,
                    i have a session bean and entity bean.i ma looking entitybean from session bean.when iam deploying i am not able to see them in the server:8082 and the place where u mentioned.

                    java:comp namespace of the CustomerBean bean:
                    +- env (class: org.jnp.interfaces.NamingContext)

                    java:comp namespace of the UserManagerBean bean:
                    +- UserTransaction (class: javax.transaction.UserTransaction)
                    +- env (class: org.jnp.interfaces.NamingContext)
                    | +- CustomerBean (class: com.xxx.ejb.CustomerLocalHome)


                    iam using same jar file for both beans. could u please tell me why it is showing me like that.shall i need to deploy each bean in a single jar??

                    plz respond asap iam struck there.

                    thanx.