Discussions

EJB programming & troubleshooting: pls.check my code regarding Serializable

  1. pls.check my code regarding Serializable (5 messages)

    I made a rowset wrapper class:
    public class RowSetAdaptor extends java.lang.Object implements Serializable
    {
      private CachedRowSetImpl rowset;
        public RowSetAdaptor()
        { try{

    rowset = new CachedRowSetImpl();

    }catch(Exception e){System.out.println("constructor:"+e);}


        }


        public void populate(ResultSet data)
        {
            
    try{
    rowset.populate(data);
    }catch(Exception e){System.out.println("populate:"+e);}
        }


        public boolean next()
        {
         
    try{
    return rowset.next();
    }catch(Exception e){return false;}
        }


        public String getString(String columnName)
        {
             try{
    return rowset.getString(columnName);
    }catch(Exception e){return null;}
        }


        public String getString(int columnIndex)
        {
            
    try{
    return rowset.getString(columnIndex);
    }catch(Exception e){return null;}
        }


        public int getInt(String columnName)
        {
            
    try{
    return rowset.getInt(columnName);
    }catch(Exception e){return 0;}
        }


        public int getInt(int columnIndex)
        {
             try{
    return rowset.getInt(columnIndex);
    }catch(Exception e){return 0;}
        }

       ....

    I have EJB method retrieve database and return a RowSetAdaptor,in jsp I get this RowSetAdaptor object and display the content.
    this works fine in JBoss
    but when I deploye in to sybase easerver,I got error:org.omg.CORBA.MARSHAL: java.io.NotSerializableException:

    is there any more I have put in my RowSetAdaptor to make sure it is Serializable
  2. All the instance variables your Serializable object must also Serializable. Is CachedRowSetImpl Serializable?

    If not, you will have to (a) copy the data into a serializable collection (e.g. a HashMap) or (b) mark the variable as transient (but this means you lose the data when the RowSetAdapter is serialized).
  3. thank you. the CachedRowSetImpl is Serializable,it is sun's implementation of rowset. I tryed to send CachedRowSetImpl from EJB to JSP,it works,so looks like only thing is the wrapper.
    even I put the transit for CachedRowSetImpl,I got the same error
    what's wrong with the wrapper?
  4. I am not sure. The only requirements to make something serializable are:

    1) The class implement the Serializable interface.

    2) The superclass be (a) Serializable or (b) have a no-parameter exception.

    3) All the instance variables be Serializable or transient.

    Your class meets all of these criteria.

    Since the error message you are getting is a CORBA marshalling exception rather than a java.io.IOException, my best guess is that the problem is CORBA related.

    It is possible that the problem is being caused by your overloaded methods: two getString() methods, one with a String parameter, one with an int parameter. I have heard that CORBA sometimes has difficulty with overloaded methods. Try "getStringByName(String)" and "getStringByColumn(int)".
  5. I suspect there is some reachable reference in the CachedRowSetImpl (maybe some object stored in it is not serializable) that is not serializable. I don't think the problem is with the two classes visible here (RowSetAdaptor and CachedRowSetImpl).

    I will modify the following rules:
    2) The superclass be (a) Serializable or (b) have a no-parameter exception.
    should say
    2) The superclass be (a) Serializable or (b) have a no-parameter constructor.
    which is what I suspect Paul meant to say.

    3) All the instance variables be Serializable or transient
    to
    3) all objects reachable through non-static, non-transient fields must be serializable or transient.

    Note that while the formal type of the field may not be serializable, it is OK as long as the instance assigned to it is of a type that is serializable. Also note that the non serializable class may be very deep down the graph of reachable objects. It is unfortunate that the exception does not print out the name of the class that is not serializable. Try to see if you can turn on debugging to get more information.

    Unlike remote interfaces, a Serializable class does not require all methods to throw RemoteExceptions, so I don't believe that's the problem.

    the getString overload observation is also not an issue, as there are ways the infrastructure handles overloading. Furthermore the methods of a value object do not affect its marshaling in RMI/IIOP.
  6. try throwing a RemoteException in all your methods