EJB design: How to pass Object by Reference over the network in ejb?

  1. Dear Friends,
              I am calling a method of session bean in ejb client. I am passing a vector to this method. I want the vector to be passed by reference so that whatever changes I make in it in session bean method, these are reflected beack in client without returning the vector.
    In general, how to pass the objects by reference over the network?

  2. Varun,

      In RMI (the communications protocol used by EJB), the vector you pass over gets serialized. That is, a complete copy of its current state gets passed over the wire to the EJB, which "deserializes" it into a copy of the original vector. I don't know of any way to pass by reference. You will just have to return a vector.

  3. Support!
  4. Hi,
    One Basic concept in RMI is nothing like pass by referance.All the parameters paased to the method are pass by value only.
  5. You can instantiate RMI object which wraps your Vector and use it. This will achieve 'pass by reference' functionality.
  6. Hi Dimitri Rakitine,

    Can you please elaborate on this point.
  7. You can create RMI remote object in your client and use it as a parameter when calling your server - that will achieve 'pass by reference' behaviour.
  8. For a heavyweight component making it an EJB could be a good solution, too. Maybe your vector is semantically just a property of a broader business logic object...
  9. I believe that RMI simulates pass by reference by passing a stub of the remote object by value. That is, it serializes the stub and passes the stub to the other side.

    See page 521 of Mastering EJB which is downloadable from this site.

  10. You should see page 572 of the new version of the book:Mastering Enterprise JavaBeans 3.0