Tag Archives: jpa

When and why JPA entities should implement Serializable interface?

Answers from Stackoverflow:

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

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.

Advertisements