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.
Asked: 2022-01-01 11:00:00 +0000
Seen: 15 times
Last updated: Jun 26 '21