File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Hibernate and Serializable

 
Janki Shah
Ranch Hand
Posts: 136
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why do we require to implement Serializable for persistent classes in hibernate?
 
Bill Gorder
Bartender
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have a look here:

http://docs.oracle.com/cd/E19159-01/819-3669/bnbpz/index.html

Under Requirements for Entity Classes

If an entity instance be passed by value as a detached object, such as through a session bean’s remote business interface, the class must implement the Serializable interface.


In short it is not a requirement, but since this is a common occurrence (HTTP Session, RMI etc) it is a best practice.
 
Janki Shah
Ranch Hand
Posts: 136
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Bill for the reply and the link. It might take some time to understand the content of the link since I am new to hibernate.
But one more question, In which condition we should implement Serializable and in which condition it's ok not to implement ?

 
Bill Gorder
Bartender
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Some examples of when serializing would be required is if you are storing detached entities in an HTTP session, passing it over the wire or perhaps you have a multi node cluster. If not you could get away without it but as I said your really should just make them serializable as these types of situations are commonplace and its recommended by the spec that you do so.

So my advice is rather than spending too much time determining if it is strictly required in your case just do it

I do think it worthwhile to understand the concept of serialization and why its necessary, but that question would be more appropriate for the Java in General forum.
 
Paul Clapham
Sheriff
Pie
Posts: 20166
24
MySQL Database
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let's put it the other way around: in what circumstances would it be detrimental to your design if your class implemented Serializable?

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic