The @Embeddable annotation marks a class as a value type whose fields are stored as columns in the table of the entity that contains it. It has no identity and no table of its own, so you use it to group related attributes such as an address or a money amount and reuse that group across several entities.
It is part of Jakarta Persistence (JPA). Since Jakarta EE 9 and Spring Boot 3, the package is jakarta.persistence; older code uses javax.persistence, which is the only difference in the import.
An embeddable class models a part of an entity rather than an entity itself. Compared with @Entity:
| Aspect | @Entity | @Embeddable |
|---|---|---|
| Identity | Has an @Id | None |
| Table | Own table | Columns in the owner's table |
| Lifecycle | Independent | Tied to the owning entity |
| Can be queried directly | Yes | No, only through its owner |
| Can be shared by reference | Yes | No, each owner has its own copy |
Because the value has no identity, deleting the owner deletes the embedded data, and two owners never share the same embedded row.
Declare the class with @Embeddable, then include it in an entity as a field, optionally marked with @Embedded. Hibernate detects embeddable fields without @Embedded, but adding it documents the intent.
The customer table gets street, city, state and postal_code columns next to id and name. There is no join, so reading the address costs nothing extra.
The JPA specification requires a no-argument constructor that is public or protected. Hibernate 6 also supports Java records as embeddables, which gives you an immutable value type without boilerplate:
When an entity has two fields of the same embeddable type, the column names would collide. @AttributeOverrides renames them.
Override every attribute that would clash, including state and postalCode in a real mapping. The overrides apply only to that field, so the Address class stays reusable.
An embeddable can also serve as a composite key. The key class must implement equals and hashCode and should be Serializable.
Use @EmbeddedId when the key class is a single field of the entity, and @IdClass when you prefer to repeat the key fields in the entity.
You navigate into an embedded value with a dot in JPQL and Spring Data derived queries.
The repository method name findByAddressCity walks from address to city, and the same path works in Sort and Specification objects.
null, not as an empty object. Handle that in getters.@ElementCollection, but avoid deep nesting.@EmbeddedId.Usually not, because the provider detects it, but it is good practice to add it. You need @Embedded explicitly together with @AttributeOverride to be clear about intent.
No. Its fields become columns of the owning entity's table. Only collections of embeddables, mapped with @ElementCollection, use a separate collection table.
Yes, with Hibernate 6 and later. Records give you an immutable value with a canonical constructor.
An entity has an identity and its own table. An embeddable has neither and exists only as part of another entity.
@Embeddable lets you group fields into a reusable value type stored in the owner's table. Use @Embedded to include it, @AttributeOverride to rename columns when you reuse it, and @EmbeddedId for composite keys. Keep embeddables small, immutable where possible, and import from jakarta.persistence on current stacks.