Results 1 to 1 of 1
  1. #1
    nineball is offline Member
    Join Date
    Mar 2008
    Posts
    1
    Rep Power
    0

    Default bean with flexible version ability

    Hi,

    I am trying to deserialize a bean from a database (Oracle blob). I want to have some flexibility, meaning that I can store objects of the same class but different versions, and I can cast them into just one class when I read them back.

    For example, initially I wrote an Employee object into the DB, and I had a local Employee class.

    class Employee {
    String name;
    int age;

    String getName() {...}
    void setName(String s) {...}
    int getAge() {...}
    void setAge(int i) {...}
    }


    Later, you might want to add a new field 'payRise' to the class, and use the new corresponding getPayRise() and setPayRise().

    In the DB, you still want to have both objects from both versions of the same class. Is there a way to still read the old object using the new Employee class? (so now we can read both versions) Currently I'm still having the InvalidClassException (serialVersionUID difference) even after manually setting the serialVersionUID .

    More code example:

    resultSet = statement.executeQuery("SELECT * FROM DB WHERE VERSION = 1")
    resultSet.next();
    Employee e = (Employee) read (resultSet, "EMPLOYEE_OBJECT")

    // and also..
    resultSet = statement.executeQuery("SELECT * FROM DB WHERE VERSION = 2")
    resultSet.next();
    e = (Employee) read (resultSet, "EMPLOYEE_OBJECT")



    read() is the usual deserialization:
    public static Object read(ResultSet resultTransactionSet, String column)
    throws SQLException, IOException, ClassNotFoundException {

    byte[] buf = resultTransactionSet.getBytes(column);

    if (buf != null) {

    ObjectInputStream objectIn = new ObjectInputStream(
    new ByteArrayInputStream(buf));

    return objectIn.readObject();
    }

    return null;
    }


    So is there a way to accomplish this? :) Thanks
    Last edited by nineball; 03-26-2008 at 11:02 AM.

Similar Threads

  1. Replies: 0
    Last Post: 04-07-2008, 09:14 PM
  2. Replies: 0
    Last Post: 03-30-2008, 11:03 AM
  3. Replies: 0
    Last Post: 09-26-2007, 09:36 PM
  4. how to remove an old version of JDK
    By tommy in forum New To Java
    Replies: 2
    Last Post: 07-30-2007, 09:59 AM
  5. to version
    By Alan in forum New To Java
    Replies: 2
    Last Post: 05-31-2007, 07:05 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •