@AttributeOverride is a JPA annotation that changes the column mapping of one persistent attribute that comes from a mapped superclass or an embeddable class. You use it to rename a column or change its length or nullability for a specific entity without touching the shared class. @AttributeOverrides groups several overrides, and since JPA 2.2 you can also repeat @AttributeOverride directly.
It applies to @MappedSuperclass and @Embeddable types. It does not rename attributes inherited from another @Entity.
Shared fields often live in a base class or a value object that many entities reuse. The base class declares one default column name, but a particular entity may need a different one, for example to fit an existing schema. @AttributeOverride puts that exception on the entity, so the shared class stays generic.
The annotation has two elements:
name: the attribute to override. For an embedded attribute use dot notation such as address.street.column: a @Column that replaces the mapping. You can set name, length, nullable, unique and similar properties.The package is jakarta.persistence in Jakarta Persistence 3 and later (Hibernate 6, Spring Boot 3 and 4). Older code used javax.persistence with the same API.
Define the shared fields once in a mapped superclass:
Override the mapping in the entity that needs a different column:
The employee table gets a column employee_name with length 100, while another entity extending BasePerson keeps name with length 50.
To override several attributes, repeat the annotation or wrap them:
On older JPA versions, wrap them in @AttributeOverrides({ ... }) instead.
The most common use is reusing one @Embeddable twice in the same entity. Both copies would otherwise map to the same column names and fail.
The customer table now contains billing_* and shipping_* columns. Placing the annotation on the field limits it to that one embedded attribute. Placed on the entity class, it applies to attributes inherited from a mapped superclass.
A frequent mistake is to use @AttributeOverride on an entity that extends another entity:
In entity inheritance the attributes of Person belong to the Person mapping. With SINGLE_TABLE and JOINED the columns are shared by design, so a subclass cannot give them a different name. The spec defines overrides for mapped superclasses and embeddables only. If you need different columns, move the shared fields into a @MappedSuperclass or change the design.
@AttributeOverrides is the container that holds an array of @AttributeOverride. Since JPA 2.2 @AttributeOverride is repeatable, so you can often skip the container.
It replaces the @Column details such as name, length and nullability. To change the Java type mapping, use a converter or a different attribute instead.
Use dot notation in name, for example address.street, on the entity or the embedding field.
No. @AssociationOverride changes the join column or join table of a relationship, while @AttributeOverride changes a basic attribute column.
Use @AttributeOverride when a mapped superclass or an embeddable gives you a default column that one entity must change. Prefer jakarta.persistence imports, repeat the annotation for several fields, use dot notation for nested embeddables, and remember it does not apply to attributes inherited from another entity.