@Embeddable class Address { string zip; string city; string streetAddress; } @Table("customers") class Customer { @Id @Generated long id; @Embedded("shipping") Address shipping; // Adds columns like: shipping_zip, shipping_city @Embedded("billing") Address billing; // Adds columns like: billing_zip, billing_city }
While the @Embeddable annotation is applied to a type which can be included in a class in order to add its properties as its own, the @Embedded annotation is used for the field itself.
If there is only one @Embeddable member in a class, then this annotation is implied and optional. However, @Embedded can include a prefix, which is needed to distinguish multiple embedded properties that have the same type.