Top Description Methods
jakarta.persistence

public @Interface Embeddable

extends Annotation
Annotations
@Documented
@Target:TYPE
@Retention:RUNTIME
Imports
java.lang.annotation.Target, .Retention, .Documented

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:

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:

@Embeddable public class EmploymentPeriod { @Temporal(DATE) java.util.Date startDate; @Temporal(DATE) java.util.Date endDate; ... }
@Embeddable
public class EmploymentPeriod {
    @Temporal(DATE) java.util.Date startDate;
    @Temporal(DATE) java.util.Date endDate;
    ...
}

Example 2:

@Embeddable public class PhoneNumber { protected String areaCode; protected String localNumber; @ManyToOne protected PhoneServiceProvider provider; ... } @Entity public class PhoneServiceProvider { @Id protected String name; ... }
@Embeddable
public class PhoneNumber {
    protected String areaCode;
    protected String localNumber;
    @ManyToOne
    protected PhoneServiceProvider provider;
    ...
}

@Entity
public class PhoneServiceProvider {
    @Id
    protected String name;
    ...
}

Example 3:

@Embeddable public class Address { protected String street; protected String city; protected String state; @Embedded protected Zipcode zipcode; } @Embeddable public class Zipcode { protected String zip; protected String plusFour; }
@Embeddable
public class Address {
    protected String street;
    protected String city;
    protected String state;
    @Embedded
    protected Zipcode zipcode;
}

@Embeddable
public class Zipcode {
    protected String zip;
    protected String plusFour;
}
Since
1.0
See Also
Embedded, EmbeddedId

Method Summary

Inherited from java.lang.annotation.Annotation:
annotationTypeequalshashCodetoString