@Repeatable(value=AttributeOverrides.class) @Target(value={TYPE,METHOD,FIELD}) @Retention(value=RUNTIME) public @interface AttributeOverride
Basicプロパティもしくはフィールド、Idプロパティもしくはフィールドのマッピングを上書きするために使用します。
マップドスーパークラスを継承したエンティティや組み込みフィールドもしくはプロパティを持つエンティティのマップドスーパークラスや組み込みクラス (もしくはその属性のひとつで定義された組み込みクラス)で定義された基本マッピングやIDマッピングを上書きするために適用できます。
組み込みクラスのインスタンスを含む要素コレクションやキーもしくは値が組み込みクラスであるMapコレクションに適用することができます。
MapにAttributeOverrideを適用するときはマップのキーもしくはマップの値の一部として指定するために、
上書きされる属性の名前のプレフィックスとして"key."もしくは"value."を使用する必要があります。
複数の埋め込みレベルのマッピングを上書きするには、組み込み属性内の属性を示すためにname要素にドット(".")表記形式を使用する必要があります。
ドット表記で使用される各識別子の値は、それぞれの組み込みフィールドもしくはプロパティの名前です。
AttributeOverrideが指定されていない場合は、カラムにはオリジナルのマッピングと同じマッピングがされます。
Example 1:
@MappedSuperclass
public class Employee {
@Id protected Integer id;
@Version protected Integer version;
protected String address;
public Integer getId() { ... }
public void setId(Integer id) { ... }
public String getAddress() { ... }
public void setAddress(String address) { ... }
}
@Entity
@AttributeOverride(name="address", column=@Column(name="ADDR"))
public class PartTimeEmployee extends Employee {
// address field mapping overridden to ADDR
protected Float wage();
public Float getHourlyWage() { ... }
public void setHourlyWage(Float wage) { ... }
}
Example 2:
@Embeddable public class Address {
protected String street;
protected String city;
protected String state;
@Embedded protected Zipcode zipcode;
}
@Embeddable public class Zipcode {
protected String zip;
protected String plusFour;
}
@Entity public class Customer {
@Id protected Integer id;
protected String name;
@AttributeOverrides({
@AttributeOverride(name="state",
column=@Column(name="ADDR_STATE")),
@AttributeOverride(name="zipcode.zip",
column=@Column(name="ADDR_ZIP"))
})
@Embedded protected Address address;
...
}
Example 3:
@Entity public class PropertyRecord {
@EmbeddedId PropertyOwner owner;
@AttributeOverrides({
@AttributeOverride(name="key.street",
column=@Column(name="STREET_NAME")),
@AttributeOverride(name="value.size",
column=@Column(name="SQUARE_FEET")),
@AttributeOverride(name="value.tax",
column=@Column(name="ASSESSMENT"))
})
@ElementCollection
Map<Address, PropertyInfo> parcels;
}
@Embeddable public class PropertyInfo {
Integer parcelNumber;
Integer size;
BigDecimal tax;
}
Embedded,
Embeddable,
MappedSuperclass,
AssociationOverridepublic abstract java.lang.String name
public abstract Column column
Translated by @megascus.