What to do if something I need in EJB is not serializable?


EJB programming & troubleshooting: What to do if something I need in EJB is not serializable?

  1. Hello,

    I'm converting an existing framework to EJB, but I don't know what to do with the classes which use parameters with non serializable type. Anyone has experience here?
    Thanx in advance!
  2. off the top of my head

    * send serializable objects to the ejb that essentially represents the nonserializable object..the ejb doesnt really care what the object it, it will just do the work...then the ejb will have to return some data to the client and the client will have to reconstruct the nonserializable object
    * make those objects remote objects (rmi, corba, ejb)

  3. Thanks for your kind reply!
    But the problem I have is that I don't always have the control of the classes, sometimes it's just some exotic libraries. And as far as I know, there's no way to tell for sure whether a class is serializable or not (I do know some basic rules, like threads/reflection/io are not serializable etc.) until the compiler or the appserver complains:-(
    Are the XML libs serializable, xalan, xerces, jdom etc.? I really wish there's a simple way to tell which would work with EJB and which not, and if not, what to do then? I think if a class is not serializable by definition, then I cann't make it serializable in ANY way, right?
    The whole thing really looks like a hit and miss for me, and we have more than 180 Java classes here in our framework, it would mean a lot if we could find some easy walk-around for the serializable problematic.
    Many thanks in advance.
  4. Still need the answer:-( Anyone care to help? Thanks in advance!
  5. Serializable is essential in EJB. You have to create serializable copy classes to pass data between your EJB beans. In the beans you call your existing framework non-serializable classes (or classes that you can't make serializable). Copy-class approach is well documented.
    See our framework JavaDoc http://www.zhanra.com/javadoc/ - if you need an example.

    Kevin Leong