The @Embedded annotation tells JPA that a field of an entity holds an instance of an @Embeddable class, and that the fields of that instance should be stored as columns in the owning entity's table. It lets you group related attributes, such as an address or a name, into one object without creating a separate table or entity.
In practice @Embedded is optional when the field type is already annotated with @Embeddable, because the persistence provider detects it. Adding it makes the mapping explicit and is required when you need to customise the columns on the field.
An embeddable class has no identity. The owning entity contains it by value, so there is one copy per owner and no joins on read. The relationship between the two annotations is simple:
@Embeddable goes on the class that defines the value type.@Embedded goes on the field or getter in the entity that uses it.@EmbeddedId goes on the field when the embeddable is the primary key.Imports come from jakarta.persistence on Spring Boot 3 and Jakarta EE 9 and later. Older projects use javax.persistence with the same annotation names.
The generated table contains id, name, email and phone. When you load an Employee, JPA builds a ContactInfo from the email and phone columns and assigns it to the contact field.
By default the embedded fields use the embeddable's own column names. Use @AttributeOverride to rename them, which is how you embed the same type twice in one entity.
Without the overrides, both fields would map to email and phone and the mapping would fail with a duplicate column error. The override is local to the field, so ContactInfo stays unchanged elsewhere.
| Question | Embedded value | Separate entity |
|---|---|---|
| Has its own identity | No | Yes |
| Own table | No | Yes |
| Shared between owners | No | Yes |
| Extra query or join | No | Yes, unless fetched together |
| Lifecycle | Same as owner | Independent |
Use an embedded value when the data belongs to exactly one owner and is always loaded with it. Use an entity with @OneToOne or @ManyToOne when other rows must reference it, when it changes independently, or when it is large.
Embeddables can contain other embeddables, and the columns are flattened into the same table. Keep the nesting shallow so the table stays readable.
If all columns of an embedded value are null, Hibernate returns null for the field instead of an object with null properties. Code that calls employee.getContact().getEmail() can therefore throw a NullPointerException. Initialise defensively or return Optional from your accessor.
You query embedded attributes with a dot path, in JPQL or in derived repository methods:
findByContactEmail resolves to the email property of the contact field, with no join, since the value lives in the same row.
Hibernate 6 supports Java records as embeddables, giving an immutable value with little code:
Replace the whole Address when it changes rather than trying to mutate it, which also makes dirty checking predictable.
No. If the field type is annotated with @Embeddable, JPA treats the field as embedded anyway. Add @Embedded for clarity and whenever you use attribute overrides.
Yes, but you must override the column names for at least one field with @AttributeOverride, otherwise the columns collide.
You cannot annotate third-party types. Wrap the data in your own @Embeddable class, or use an AttributeConverter to store it in a single column.
For a collection of value types, use @ElementCollection with an embeddable class. That stores the values in a separate collection table, not in the owner's row.
@Embedded places an @Embeddable value object inside an entity so its fields become columns of the owner's table. It removes the need for extra tables and joins for owned data, supports column renaming with @AttributeOverride, and works well with immutable records on Hibernate 6. Choose an entity instead when the data needs its own identity or lifecycle.