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:
r
esultSet = 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