| Author |
Is there any need to write SerialVersionId inside my HttpServlet?
|
Hemant Agarwal
Ranch Hand
Joined: Nov 21, 2005
Posts: 138
|
|
Hello friends, Is there any need to write SerialVersionId inside my servlet which is extending HttpServlet. I am using eclipse id. It is showing hints to add that. When we need to write SerialVersionId.
|
 |
Adeel Ansari
Ranch Hand
Joined: Aug 15, 2004
Posts: 2874
|
|
serialVersionUId should be defined in a serialized object. As we know HttpServlet implements serializable interface. Therefore, eclipse always gives you the hint to add serialVersionUId. The serialVersionUID only comes into play when serializing/deserializing objects whose classes have changed. This link might be helpful to you. http://c2.com/cgi/wiki?AlwaysDeclareSerialVersionUid [ December 19, 2005: Message edited by: Adeel Ansari ]
|
 |
Adeel Ansari
Ranch Hand
Joined: Aug 15, 2004
Posts: 2874
|
|
|
Its worth reading this thread.
|
 |
Hemant Agarwal
Ranch Hand
Joined: Nov 21, 2005
Posts: 138
|
|
What could went wrong if I didn't give serialVersionId ? Please give detail explanations + links
|
 |
Paul Sturrock
Bartender
Joined: Apr 14, 2004
Posts: 10336
|
|
|
Nothing is likely to go wrong. If there isn't a serialVersionId defined in your class, the JVM will derive one based on the features of your class. You will have an issue if you serialize an object of a type to some persistant store, change a feature of the class and reload it from that store. The features of the class will be different, so the derived serialVersionId will be different. .
|
JavaRanch FAQ HowToAskQuestionsOnJavaRanch
|
 |
Hemant Agarwal
Ranch Hand
Joined: Nov 21, 2005
Posts: 138
|
|
|
So in order to avoid that issue, What should we do? What are the things that we should take care of ?
|
 |
Ben Souther
Sheriff
Joined: Dec 11, 2004
Posts: 13410
|
|
If the JVM that serialized the objects is the same one that will de-serialize them - as is the case with session persistence across app server restarts - then you will probably never see an issue. If you are serializing your objects and passing them to another JVM - such as an applet or another servlet container - and that JVM has a copy of the class file that was compiled with a different version of javac, you could see some serialization exceptions.
|
Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
|
 |
 |
|
|
subject: Is there any need to write SerialVersionId inside my HttpServlet?
|
|
|