public @interface ColumnOverride
Overrides the column mapping for a specific property within an embeddable object.
This annotation is used within the Embedded annotation to customize how properties of
an embeddable object are mapped to database columns. It allows you to override the default column
name and attributes (such as insertable, updatable, and quote) for individual properties when the
embeddable is embedded in an entity.
This is particularly useful when:
- The same embeddable type is used multiple times in an entity and requires different column names to avoid conflicts
- The column names in the database don't match the default naming conventions
- You need to control the behavior of specific columns (e.g., making them read-only)
@Embeddable
public class Address {
String street;
String city;
String zipCode;
}
@Entity
public class Employee {
@Id
Integer id;
@Embedded(columnOverrides = {
@ColumnOverride(name = "street", column = @Column(name = "HOME_STREET")),
@ColumnOverride(name = "city", column = @Column(name = "HOME_CITY")),
@ColumnOverride(name = "zipCode", column = @Column(name = "HOME_ZIP"))
})
Address homeAddress;
@Embedded(columnOverrides = {
@ColumnOverride(name = "street", column = @Column(name = "WORK_STREET")),
@ColumnOverride(name = "city", column = @Column(name = "WORK_CITY")),
@ColumnOverride(name = "zipCode", column = @Column(name = "WORK_ZIP"))
})
Address workAddress;
}
- See Also:
-
Required Element Summary
Required Elements
-
Element Details
-
name
String nameThe name of the property in the embeddable class whose column mapping should be overridden.This must match exactly the name of a field in the embeddable class.
- Returns:
- the property name in the embeddable class
-
column
Column columnThe column definition that overrides the default column mapping for the specified property.This allows you to specify a custom column name and control column attributes such as insertable, updatable, and quote.
- Returns:
- the column definition to use for the property
-