• Post Reply Bookmark Topic Watch Topic
  • New Topic

What Is The Defaul Serial Version ID??  RSS feed

 
Alan Hermin
Ranch Hand
Posts: 290
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello ranchers........i do not know if i am posting at a correct forum/section..
i am using BEA Workshop at my application, but when making a new Class, there is a warning message may be that the IDE advice me to make a static vairable like this mesage:
the serialzable class <CLASSNAME> does not declare a static final serialVersionUID field of type long


what message IS?

regards
[ August 08, 2006: Message edited by: Ala'a Hendi ]
 
Dini Bang
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I had the same problem 2day...
Then one of my colleague told tht which ever class implements serializable it must be declare static final serialVersionUID as some long value.
As it is used for some version checking while execution.
Note : not declaring it is just a warning.
 
Carl Trusiak
Sheriff
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From Serializable Interface JavaDoc:

If a serializable class does not explicitly declare a serialVersionUID, then the serialization runtime will calculate a default serialVersionUID value for that class based on various aspects of the class, as described in the Java(TM) Object Serialization Specification.


From Java(TM) Object Serialization Specification:

The serialVersionUID is computed using the signature of a stream of bytes that reflect the class definition...

It then goes on to give the full formula. Basically an SHA hash of class name, Interfaces, method names, attributes etc.
[ August 08, 2006: Message edited by: Carl Trusiak ]
 
Campbell Ritchie
Marshal
Posts: 56225
171
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From C Horstmann, G Cornell, Core Java 2 (7/e) vol I: Fundamentals, Upper Saddle River NJ: Sun Microsystems Press (Prentice-Hall) (2005):-
[page 666]
Understanding the Object Serialization File Format
...
SHA is a fast algorithm that gives a "fingerprint" to a larger block of information.
...
It is ... very likely that the class fingerprint will change if the data fields or methods change in any way.
Java can then check the class fingerpritn to protect us from the following scenario: An object is saved to a disk file. Later, the designer of the class makes a change, for example, by removing a data field. Now the data layout on the disk no longer matches the data layout in memory. If the data were read back in its old form, it could corrupt memory. Java takes great care to make such memory corruption close to impossible. Hence, it checks, using the fingerprint, that the class definiton has not changed when it restores an object. It does this by comparing the fingerprint on disk with the fingerprint of the current class.
Is that any help?
 
Vladimir Nesov
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There's serialver tool in the same directory where java is which can calculate current serialVesionUID. Point in defining this variable is to enable compatibility with old versions your your class, that is if you do define this variable you should be prepared to read serialized oblects of earlier versions with the same serialVesionUID.
 
Mr. C Lamont Gilbert
Ranch Hand
Posts: 1170
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think often people fixate on serialization as if it means read/write to/from storage. But that is not what serialization means. Sometimes its good to have the serialversion UID change when the class itself does.

In any event, its a 'friendly' warning to add the serialVersionUID by folks that insist it should always be there.
 
Vladimir Nesov
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Problem is that it changes even when fields set doesn't change. Even if serialization is used to transfer objects, there may be different versions of application of connection ends. Only case when it doesn't matter is some sort of spooling, but when you are able to store most of application data there appears some new application for storing/sending, so compatibility again.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!