8 Replies Latest reply on Nov 2, 2003 1:52 PM by kkaal

    Reference EJB Components

    kkaal

      Hi,

      I am using JSP as client and from there creating from the first page

      1. EJB UserDataBean with lookup and home.create()

      then the user goes to next page which creates

      2. EJB DoSomethingBean with lookup and home.create()

      Now, I would like to having DoSomethingBean use some data from UserDataBean. Presently, the client drags these data from UserDataBean and transfers it to DoSomethingBean.

      How would it be possible for DoSomethingBean to find UserDataBean in the EJB container and reference it? Would it be possible to store the referece under a unique name in JNDI so that ohter beans could find it there? And how should it be done?

      All Books only tell me how to create new instances from JNDI.

      Thanks for your help

      Klaus

        • 1. Re: Reference EJB Components
          jonlee

          Rather than do that, is it not possible to store your data in the session? This would save the extra cost of doing the lookup and retrieval.

          You could also build an object cache bound to JNDI, look up the cache and obtain the data with the appropriate hash key (or whatever the key you use). You need to take the care to ensure that the right user picks up the data. So the session storage is still probably the best solution.

          Hope that helps.

          • 2. Re: Reference EJB Components
            kkaal

            Thanks JonLee,

            good hint, but I do NOT want to have the client transport the data. I would like my EJB have know each other, because my problem is a bit more complex than the described abstracted one. And: I want to have a liteweight client with simple interface to EJB.

            There must be a way for the EJB in the container to contact each other directly.

            thnaks for further help

            Klaus

            • 3. Re: Reference EJB Components

              What exactly is the problem with using normal EJB semantics with bean lookups from the naming service?

              -- Juha

              • 4. Re: Reference EJB Components
                kkaal

                My straight question: How do I store the reference of an EXISTING instance or an EJB in JNDI for allowing other EJB to find and access this INSTANCE? I would care for an unique name of the instance in JNDI.

                Thanks for your help

                Klaus

                • 5. Re: Reference EJB Components

                  See the spec for <ejb-ref> elements.

                  Or pass the proxy as an argument to your method.

                  -- Juha

                  • 6. Re: Reference EJB Components
                    kkaal

                    So, in essence, is it allowed for an EJB instance (object) to bind itself to a JNDI context by optaining the own handle and bind it to a unique identifier in a subcontext of JNDI? Like

                    (111 would be unique user-id)
                    java:ejb/myapp/111/usermanager

                    My other bean would know the user-id and could find the handle of the adjacent usermanger

                    • 7. Re: Reference EJB Components

                      It would work with an entity bean that has a shared identity. It does not make any sense to do so however, since the home proxy with the finders is already bound to JNDI.

                      It makes no sense for stateless session beans as there is no identity associated with the instance. Any one you get via the home proxy via JNDI would work.

                      Stateful session beans are restricted by the spec to only allow single client to access them. No concurrent access is allowed so it makes little sense to share the proxy in a global naming space like JNDI.

                      From the sound of things, what you're attempting to do seems to me there's something fundamentally flawed with the applications architecture.

                      -- Juha

                      • 8. Re: Reference EJB Components
                        kkaal

                        Juha, thanxs for your help and patience.

                        Klaus