The @Embeddable annotation marks a class whose fields can be stored as part of another entity's table instead of in a table of their own. The owning entity includes it with @Embedded, and its columns appear in the owner's table. It is the standard JPA way to model value objects such as an address or money amount, and to build composite primary keys.
An embeddable has no identity and no lifecycle of its own. It lives and dies with the entity that owns it.
JPA entities map to tables and have an identity. Many concepts, such as a postal address, do not deserve their own table, but you still want them grouped in one reusable class. Annotate that class with @Embeddable (from jakarta.persistence in Jakarta Persistence 3.x, javax.persistence in older versions) and JPA maps its fields as columns of the owning table.
Since Spring Boot 3 and Hibernate 6, the package is jakarta.persistence. Code written for Spring Boot 2 uses javax.persistence.
Now embed it in an entity:
The customer table gets the columns id, name, street, city and postal_code, with no separate address table or join. The @Embedded annotation is optional when the class itself is annotated with @Embeddable, but writing it makes intent clear.
If the same embeddable is used twice in one entity, the column names would collide. Use @AttributeOverride to rename them.
An embeddable class can serve as a composite key when used with @EmbeddedId. The key class must be serializable and must implement equals() and hashCode().
Records are supported as embeddables in Hibernate 6.2 and later, and they give you correct equals() and hashCode() for free. On older versions, use a regular class with a no-argument constructor and implement both methods yourself. The alternative to @EmbeddedId is @IdClass, which keeps the key fields directly on the entity.
| Rule | Detail |
|---|---|
| Constructor | A no-argument constructor is required (it can be protected) for classes, unless you use a record on a supporting provider |
| Identity | No @Id of its own, except when used as an embedded key |
| Relationships | Embeddables may contain basic fields and, with care, associations |
| Nesting | An embeddable can contain another embeddable |
| Collections | Use @ElementCollection to hold a collection of embeddables |
| Null handling | If all columns are null, the provider typically sets the embedded field to null |
This stores each PhoneNumber in a separate table, but still without its own identity.
| Question | @Embeddable | @Entity |
|---|---|---|
| Has its own identity | No | Yes |
| Own table | No, shares the owner's | Yes |
| Queried independently | No | Yes |
| Shared between owners | No, each owner has its own copy | Yes |
Choose an embeddable when the concept is a value (compared by its fields) and belongs to exactly one owner. Choose an entity when it is referenced from several places or must be queried on its own.
No. @Embeddable on the class is enough, and @Embedded on the field is optional. Many teams add @Embedded for readability and to combine it with @AttributeOverride.
Yes, embeddables can contain @ManyToOne and similar associations, although support and behaviour vary, so test with your provider. Keep embeddables simple where you can.
JPA creates instances by reflection, so it needs a constructor without parameters. It can be protected to keep it out of your public API.
Yes. Use dot notation, for example select c from Customer c where c.address.city = :city.
@Embeddable lets you group fields into a reusable value class that is stored inside the owning entity's table. Use @Embedded with @AttributeOverride to control column names, @EmbeddedId for composite keys, and @ElementCollection for collections of values. Remember the jakarta package on current stacks, the no-argument constructor on classes, and implement equals() and hashCode() for key classes.