Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 03-26-2008, 10:59 AM
Member
 
Join Date: Mar 2008
Posts: 1
nineball is on a distinguished road
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.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
A generic framework for a flexible, multi-threaded server Java Tip java.net 0 04-07-2008 09:14 PM
How to use Inner bean definitions via nested bean elements Java Tip Java Tips 0 03-30-2008 11:03 AM
How to use Inner bean definitions via nested bean elements JavaBean Java Tips 0 09-26-2007 09:36 PM
how to remove an old version of JDK tommy New To Java 2 07-30-2007 09:59 AM
to version Alan New To Java 2 05-31-2007 07:05 PM


All times are GMT +3. The time now is 09:23 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org