Classes as LocalDateTime
from the package java.time
are value based classes. If I have an entity using such an object as a field I run into the following "problem":
Value based classes shouldn't be serialized. However, the JPA entity has to implement the interface Serializable. What is the solution for that paradox? Shouldn't someone use LocalDateTime as a field of an JPA entity? Use Date instead? This would be unsatisfying.
This problem is a Sonar rule squid:S3437
and therefore there are a lot of bugs in the project, since we changed from Date to LocalDateTime ...
Non compliant solution due to value based class usage:
@Entity
public class MyEntity implements Serializable{
@Column
private String id; // This is fine
@Column
private LocalDateTime updated; // This is not ok, as LocalDateTime is a value based class
@Column
private Date created; // This however is fine..
}
@SuppressWarnings("squid:S3437")
for now, there is a comment on dev-list (I'll try to dig it up) where it says that this might prohibit these value based classes to be moved to value based types – Kilauea