2

Simple Spring Boot entity CRUD operations work and do not implement the serializable interface. Almost every example and tutorial is not doing this and still these examples work well. But the official simple code samples use it.

Why is this interface needed and what is the simplest exemplary use case when implementing serializable interface is required?

jonrsharpe
  • 115,751
  • 26
  • 228
  • 437
mCs
  • 2,591
  • 6
  • 39
  • 66
  • Possible duplicate of [What is the purpose of Serialization in Java?](https://stackoverflow.com/questions/2232759/what-is-the-purpose-of-serialization-in-java) – Mehraj Malik Feb 27 '18 at 10:50

1 Answers1

3

You don't have to. But looking at the JPA JSR-220 spec there are cases you need to. From the 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.

So if you are passing your object via RMI then you will need to implement Serializable. I can also imagine that Serializable might be needed if you are putting your Entities inside the Session which might be serialized to disk on shutdown of the server.

Stephan
  • 922
  • 6
  • 14