• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is there any need to write SerialVersionId inside my HttpServlet?

 
Hemant Agarwal
Ranch Hand
Posts: 138
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2874
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2874
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Its worth reading this thread.
 
Hemant Agarwal
Ranch Hand
Posts: 138
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What could went wrong if I didn't give serialVersionId ?
Please give detail explanations + links
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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. .
 
Hemant Agarwal
Ranch Hand
Posts: 138
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So in order to avoid that issue, What should we do? What are the things that we should take care of ?
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic