I found that many of the serialVersionUID
of the entity classes in my project use the same value.
Now,there is no problem with my project, CURD is OK, but I think it is abnormal to use same value.
I found that many of the serialVersionUID
of the entity classes in my project use the same value.
Now,there is no problem with my project, CURD is OK, but I think it is abnormal to use same value.
There won't be any problem, as the serial number works per class.
The compiler uses the serialVersionUID
to compare the versions of the class to guarantee that the same version of that class was used for serializing it when you try to deserialize it.
The serialVersionUID
facilitates the versioning of serialized data. If you update some of those classes, you'll be able to change their serial version in order to avoid any deserialization with an older version of the class: As the UIDs won't match, the deserialization won't be successful. This guarantees data consistency through different versions of the serialized elements.
In resume: There's no issue if more than a class hold the same SerialVersionUID
(f.e: 1L
), because as said, it works per class (there's no "duplicate version UID classes" mechanism involved here). It's just as correct as two elements that were updated independently and now both hold, as a coincidence, 696969L
as their serial id: it's just each one's version number.
Declaring a permanent value, for example, 1L
, is like telling the compiler: trust me, this class didn't change, just deserialize it.
1L
is also the default serial version UID given to classes that implement the Serializable
interface, meaning "this is the first version"; It will also become the last version for those classes that won't change.
Just to finish, the serialVersionUID
of a class that does not implement Serializable
is 0L
.
Java Object Serialization Specification
If the class has defined
serialVersionUID
it is retrieved from the class.If the
serialVersionUID
is not defined by the class, it is computed from the definition of the class in the virtual machine.If the specified class is not serializable or externalizable, null is returned. The lookupAny method behaves like the lookup method, except that it returns the descriptor for any class, regardless of whether it implements Serializable. The
serialVersionUID
of a class that does not implement Serializable is0L
.