Ask Your Question
0

Is it possible to change an embedded Hibernate entity to be mandatory?

asked 2022-01-01 11:00:00 +0000

lalupa gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-06-26 12:00:00 +0000

lakamha gravatar image

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-01-01 11:00:00 +0000

Seen: 15 times

Last updated: Jun 26 '21