Annotation Interface Embeddable


@Documented @Target(TYPE) @Retention(RUNTIME) public @interface Embeddable
Declares a type whose instances are stored as an intrinsic part of an owning entity, sharing the identity of the entity. A single embeddable type may be used as the type of multiple persistent fields or properties, across several entities, and so distinct instances of an embeddable type might have owning entities of completely unrelated entity types.

The annotated type must:

  • be a non-abstract, non-final top-level class or static inner class, or a Java record type,
  • have a public or protected constructor with no parameters, unless it is a record type, and
  • have no final methods or persistent instance variables.

An enum or interface may not be designated as an embeddable type.

An embeddable class does not have its own table. Instead, the state of an instance is stored in the table or tables mapped by the owning entity.

The persistent fields and properties of an embeddable class are mapped using the same mapping annotations used to map entity classes, and may themselves hold instances of embeddable types. An embeddable class may even declare an association from its owning entity to another entity.

However, an embeddable class may not have a field or property annotated Id or EmbeddedId.

Fields or properties of an embeddable class are persistent by default. The Transient annotation or the Java transient keyword must be used to explicitly declare any field or property of an embeddable class which is not persistent.

Example 1:

Example 2:

Example 3:

Since:
1.0
See Also: