What I want:
@Embedded(nullable = false)
private Direito direito;
However, as you know there’s no such attribute to @Embeddable.
Is there a correct way to do this? I don’t want workarounds.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Embeddable components (or composite elements, whatever you want to call them) usually contain more than one property and thus are mapped to more than one column. The entire component being null can therefore be treated in different ways; J2EE spec does not dictate one way or another.
Hibernate considers component to be NULL if all its properties are NULL (and vice versa). You can therefore declare one (any) of the properties to be not null (either within
@Embeddableor as part of@AttributeOverrideon@Embedded) to achieve what you want.Alternatively, if you’re using Hibernate Validator you can annotate your property with
@NotNullalthough this will only result in app-level check, not db-level.