I am learning JPA from this tutorial.
I have some confusions in understanding the following annotations:
@Basic@Embedded
Fields of an embeddable type default to persistent, as if annotated with @Embedded.
If the fields of embeddable types default to persistent, then why would we need the @Embedded annotation
The
@Embeddableannotation allows to specify a class whose instances are stored as intrinsic part of the owning entity. This annotation has no attributes.The
@Embeddedannotation is used to specify a persistent field or property of an entity whose value is an instance of an embeddable class. By default, column definitions specified in the@Embeddableclass apply to the table of the owning entity but you can override them using@AttributeOverride:Regarding the optional
@Basicannotation, you may use it to configure the fetch type toLAZYand to configure the mapping to forbid null values (for non primitive types) with theoptionalattribute.You can also place it on a field or property to explicitly mark it as persistent (for documentation purpose).