Results 1 to 1 of 1
- 03-26-2008, 09:59 AM #1
Member
- Join Date
- Mar 2008
- Posts
- 1
- Rep Power
- 0
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? :) ThanksLast edited by nineball; 03-26-2008 at 10:02 AM.
Similar Threads
-
A generic framework for a flexible, multi-threaded server
By Java Tip in forum java.netReplies: 0Last Post: 04-07-2008, 08:14 PM -
How to use Inner bean definitions via nested bean elements
By Java Tip in forum Java TipReplies: 0Last Post: 03-30-2008, 10:03 AM -
How to use Inner bean definitions via nested bean elements
By JavaBean in forum Java TipReplies: 0Last Post: 09-26-2007, 08:36 PM -
how to remove an old version of JDK
By tommy in forum New To JavaReplies: 2Last Post: 07-30-2007, 08:59 AM -
to version
By Alan in forum New To JavaReplies: 2Last Post: 05-31-2007, 06:05 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks