java - InvalidClassException while deserializing blob field from database -
When I was trying to get the data drops from the database (mysql), I found the exception below.
java.io.InvalidClassException: com.nmsworks.cygnet.tmf.mtnm.elements.SNCUserData; Local Class Incompatible: Stream Classes Serialvarsion UID = -7634696886161105104, Local Class SerialVersion UID = -7522169448179471613
I believe some code changes after data
I believe that after the data is stored in the database, some changes are made to SNCUserData class I did not declare a default serial version UID in class. I can see what the problem is.
This will be enough to cause problems.
If I have declared a UID, then I will not get the exception.
That's right. But you can get different exceptions; Like if you have added, deleted, rearranged or changed any kind.
My question is instead of storing the object in the form of a drop in the database, there is another way to save that object so that whenever I store it and retrieve it from the database, Then I do not need to serialize and deorize the object?
The option to create a new table or tables with columns to represent the field of the object. Then type some Java code to map between objects and table rows.
I do not want to declare serial version UID in class, because it is a heavy structure, which in turn is a lot of serial objects, for which I have to declare the UID inside it.
Good, yes. But this is less than your concerns. If you start declaring a serial UID, then if you change the structure of the classes, then you may have to type custom readObject
and writeObject
to deal with it.
What is the value for it, putting things in a database is usually a bad idea. The "modern" approach to continuing complex objects is to use an object-relational mapping such as JPA (like Hibernate) or JDO, but still, you may be involved in problems if you make revolutionary changes in the continuously created sections .
Comments
Post a Comment