0

I have an MS 2000 database that is used by our primary Java 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

5
  • Have you tried just deserializing? Did it work? Commented Apr 25, 2011 at 23:54
  • yes i did and no it didn't. else i wouldn't have asked. Commented Apr 26, 2011 at 0:17
  • doesn't Hibernate just use regular Java serialization for this? What does "it didn't work" mean - what was the exception/error message, etc? Commented Apr 26, 2011 at 0:28
  • are you going us any clues? Stacktrace? Code? If not, you probably won't get a better answer. Commented Apr 26, 2011 at 3:13
  • by the way, you'd be surprised how many people do ask questions without doing the obvious thing ... like trying it for themselves, or reading the javadocs. Commented Apr 26, 2011 at 4:15

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. It was the revisions comment that helped. I was using the development code from the SCM, but the items stored in the db used an older revision in prod and the two were not compatible. I thought I was doing something completely wrong but by all the comments I was on the right track, just missing this small piece.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.