1 | initial version |
Yes, it is possible to change an embedded Hibernate entity to be mandatory by adding the @NotNull annotation on the corresponding field. For example:
@Entity
public class Customer {
@Embedded
@NotNull
private PersonalInfo personalInfo;
}
@Embeddable
public class PersonalInfo {
@NotNull
private String firstName;
@NotNull
private String lastName;
}
In the above example, the embedded entity PersonalInfo is made mandatory by adding the @NotNull annotation to its fields firstName and lastName. This ensures that whenever a Customer entity is persisted or updated, it must have a non-null PersonalInfo object that also has non-null firstName and lastName values.