Do Hibernate table classes need to be Serializable?

Is there any actual need for these classes to implement Serializable?

The JPA spec (JSR 220) summarizes it pretty well (the same applies to Hibernate):

2.1 Requirements on the Entity Class

(...)

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.

So, strictly speaking, this is not a requirement unless you need detached entities to be sent over the wire to another tier, to be migrated to another cluster node, to be stored in the HTTP session, etc.

If so, is there any tool to add a generated serialVersionUID field to a large number of classes at once

I think that you could batch this with the Serial version (Ant) Tasks.


Hibernate does not require serializable at all.


Eclipse's "Clean Up" command can do that. However, it also does a lot more so test it and refine the cleanup and format settings before using it on an entire package.