When and why JPA entities should implement the Serializable interface?
According to JPA Spec:
If an entity instance is to be passed by value as a detached object (e.g., through a remote interface), the entity class must implement the Serializable interface.
"JSR 220: Enterprise JavaBeansTM,Version 3.0 Java Persistence API Version 3.0, Final Release May 2, 2006"
You need your entities to be Serializable
if you need to transfer them over-the-wire (serialize them to some other representation), store them in http session (which is in turn serialized to hard disk by the servlet container), etc.
Just for the sake of persistence, Serializable
is not needed, at least with Hibernate.
But it is a best practice to make them Serializable
.