@TargetSE(valueSE={METHODSE,FIELDSE}) @RetentionSE(valueSE=RUNTIMESE) public @interface EmbeddedId
Embeddable というアノテーションを付ける必要があります。EmbeddedId アノテーションを使用する場合は、EmbeddedId アノテーションは 1 つだけで、Id アノテーションは使用しないでください。
AttributeOverride アノテーションは、埋め込み可能クラス内で宣言された列マッピングをオーバーライドするために使用できます。
MapsId アノテーションは、EmbeddedId アノテーションと組み合わせて使用して、派生した主キーを指定できます。
エンティティに派生主キーがある場合、AttributeOverride アノテーションは、親エンティティとの関連に対応しない埋め込み ID の属性をオーバーライドするためにのみ使用できます。
埋め込み ID クラス内で定義された関連マッピングはサポートされていません。
Example 1:
@EmbeddedId
protected EmployeePK empPK;
Example 2:
@Embeddable
public class DependentId {
String name;
EmployeeId empPK; // corresponds to primary key type of Employee
}
@Entity
public class Dependent {
// default column name for "name" attribute is overridden
@AttributeOverride(name="name", @Column(name="dep_name"))
@EmbeddedId DependentId id;
...
@MapsId("empPK")
@ManyToOne Employee emp;
}
Embeddable, MapsIdCopyright © 2019 Eclipse Foundation.
Use is subject to license terms.