3 Replies Latest reply on Oct 25, 2005 5:42 PM by evrim

    How to create Session Beans??

    mschmidke

      Hello!

      Excuse me, this seems to be a very very silly question, but I really didn't manage to find an answer for a couple of hours now ...

      How can a session bean method create and return another session bean?

      @Stateful class B {
      ...
      }

      @Stateless class A {
      ...
      public B createB() {
      ...
      }
      }


      I've simply tried "return new B();", but this cleary was no good idea. Instead of creating a remote reference, JBoss serializes the entire bean and sends it to the client. Not that good.

      What's wrong? Surely there is only missing a secret Annotation. But I did not find any example!

      Can anyone help?

      Thank you very much!

      Marcus.

        • 1. Re: How to create Session Beans??
          evrim

          try lookup(B.class); from jndi inside createB() and let jboss manage your beans.

          evrim.

          • 2. Re: How to create Session Beans??
            mschmidke

             

            "evrim" wrote:
            try lookup(B.class); from jndi inside createB() and let jboss manage your beans.


            Evrim,

            thank you, this works ... but ... do I now have to remotely publish all methods which I only want to call locally?

            @Resource SessionContext sc;
            public B createB() {
            B r=sc.lookup(B.class.getName());
            r.initialize(...);
            return r;
            }

            initialize() shall only be called locally, but B is the remote interface.

            Hmm?

            Marcus.

            • 3. Re: How to create Session Beans??
              evrim

              You cannot return your local lookup result(local proxy) to a remote vm. Its meaningless. Remote vm must lookup itself. Try using home.create(Object parameter); at the remote site. This is what j2ee suggests i think.