Do Hibernate Table Classes Need to Be Serializable

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.

Should we implement Serializable interface while making Domain Class in hibernate

If your entities are going to be transfered over a network, to be stored in an HTTP session, or even to be stored in a file on your hard disk then they must implement Serializable. Otherwise Hibernate has nothing to do with Serialization, check more here

Do Hibernate table classes need to be Serializable?

Beans serialization in JSP

When and why JPA entities should implement the Serializable interface?

This usually happens if you mix HQL and native SQL queries. In HQL, Hibernate maps the types you pass in to whatever the DB understands. When you run native SQL, then you must do the mapping yourself. If you don't, then the default mapping is to serialize the parameter and send it to the database (in the hope that it does understand it).



Related Topics



Leave a reply



Submit