How can I prevent JPA from setting an embeddable object to null just because all its fields are null?
问题 Although counterintuitive and apparently not required by the JPA standard, both Eclipselink and Hibernate go to great lengths to create the following source of NullPointerExceptions: When all fields of an object embedded in an entity are null, then they replace the field itself by null. Here is a simplified example: @Embeddable public class Period { private Date start; public Date getStart() { return start; } private Date end; public Date getEnd() { return end; } public boolean equals(Period