Reading through Serialization chapter from Effective Java, I realized I still have some Serializables here and there in my codebase (Spring Boot web app -> Spring Data -> Hibernate). The recommendation is to avoid serialization as much as one can.
Do I still need to implement Serializable?
What are the reasons for doing so in Hibernate?
If I do so, how can it be exploited?
example:
@MappedSuperclass
@Getter
public class AbstractEntityWithVersion<ID extends Serializable> implements Identifiable<ID> {
@Id
private final ID id;
@Version
@Column(name = "REC_VERSION", nullable = false)
private Long version;
protected AbstractEntityWithVersion() {
this.id = null;
}
}
public interface Identifiable<ID extends Serializable> {
ID getId();
}
Why does ID in this example have to be Serializable?
if entities doesn’t serialize then there is high chance to get corrupted when converting into an table column over the network…right?
No, before going over the network changes made to Java entities are transformed into sql statements and sent over the network using database-specific protocols. At that point in the process Java entities are not involved, so it doesn’t matter if they are Serializable.
I think this is a wrong assumption even i had for a while but then i thought hibernate really dont need the serializable interface.What do you mean by converting into a table column over network?