开发者

Deserialize object from database (Java/Hibernate)

I have an MS 2000 database that is used by our primary Jav开发者_Python百科a application. That application has a class (lets call it 'car') that is serialized and put into the database using Hibernate3 as a single field in a table. It has the default settings in Hibernate and just has a 'serialize' attribute in the .hbm.xml mapping file. As far as I can tell. It is in a different project that I don't work on, so I don't know it too intimately, but can get the source code. In any case, I am working on a second project that needs to read/use this serialized data from the database. How can I deserialize it from a different application that does not use Hibernate? I want to know how to do this using POJO to gain access to the car class attributes and data? Is there anything special that has to be done since Hibernate is currently the process by which it is serialized? Or can I just throw the returned dataset into a byte array and cast it to car - provided my car class is identical source code to the other java application's car class that serialized it? TIA


You will need to use java.io.ObjectInputStream() to read the serialized byte data from the database. Another critical thing is to have the class files (i.e. jar files or .class files) in the class path that match the same revisions of the objects stored in the database.

If you are trying this, and getting errors, you should either edit your current post to provide code and error messages, or post a new question to deal with whatever specific problem you are having with deserializing the data.


I see no reason why doing what you suggested wouldn't work.

However, this does seem like a hacky and fragile approach. Indeed, using Java serialization / deserialization is inherently fragile ... if you ever need to change the closure of classes that are being serialized.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜