2 Replies Latest reply on Mar 14, 2002 12:08 AM by Erik Sliman

    Returning custom class from session bean method

    Erik Sliman Apprentice

      Is there a prerequisite for returning an instance of a custom class from a session EJB method? I can return Collection without a problem, but when I change it to an instance of a custom class, and have it passed through the remote interface, it blows up and reports a 'null' where it calls the remote interface method.

      I tried having the custom class implement java.io.Serializable, but this didn't help.

      The class instantiates and functions without a problem on both sides of the remote call so long as I don't try to pass it via the session bean's remote interface.

        • 1. Re: Returning custom class from session bean method
          Ferdinand Che Newbie

          I am not sure I understand you correctly but if my guess is correct, you are trying to pass your custom class as a parameter to a remote interface method; and then after your remote call you are expecting to have access to the same data that would have been populated on the server.

          Eventhough, your custom class may be Serializable (assuming that it is), the component on the server and that on the client are two distinct entities. It is not possible to achieve what you appear to be looking for this way - it is simply wrong.

          If you want to insist on doing it this way, then try making your custom object itself a remote object ...

          Cheers,
          Ferdinand

          • 2. Re: Returning custom class from session bean method
            Erik Sliman Apprentice

            Here is the specific problem. I am returning a Collection of DomainBeans that is the result of a query. This works. However, since there is a possibility the query should include a "virtual global" domain, one for which you cannot instantiate an object, and therefore cannot include in the collection, I created another class that simply has two items, the collection, and a boolean indicating whether or not the "virtual global" domain should be included in the result set.

            Now I want to pass back this class, instead of the Collection. Because the class is a simply work around, it seems like overkill to try to take it further by defining it as an EJB and creating interfaces for it.

            In reality, our methods can pass back all kinds of classes, such as the String class, or other simple classes. Why should this be any different?

            I did verify that I am somehow able to do this with another simple class. So, why might it not work this time.