@TargetSE(valueSE={METHODSE,FIELDSE}) @RetentionSE(valueSE=RUNTIMESE) public @interface OneToOne
OneToOne アノテーションの mappedBy 要素を使用して、所有側の関連フィールドまたはプロパティを指定する必要があります。OneToOne アノテーションを埋め込み可能クラス内で使用して、埋め込み可能クラスからエンティティクラスへの関連を指定できます。関連が双方向で、埋め込み可能クラスを含むエンティティが関連の所有側にある場合、非所有側は OneToOne アノテーションの mappedBy 要素を使用して、埋め込み可能クラスの関連フィールドまたはプロパティを指定する必要があります。mappedBy 要素でドット("." )表記構文を使用して、埋め込み属性内の関連属性を示す必要があります。ドット表記で使用される各識別子の値は、それぞれの埋め込みフィールドまたはプロパティの名前です。
Example 1: One-to-one association that maps a foreign key column
// On Customer class:
@OneToOne(optional=false)
@JoinColumn(
name="CUSTREC_ID", unique=true, nullable=false, updatable=false)
public CustomerRecord getCustomerRecord() { return customerRecord; }
// On CustomerRecord class:
@OneToOne(optional=false, mappedBy="customerRecord")
public Customer getCustomer() { return customer; }
Example 2: One-to-one association that assumes both the source and target share the same primary key values.
// On Employee class:
@Entity
public class Employee {
@Id Integer id;
@OneToOne @MapsId
EmployeeInfo info;
...
}
// On EmployeeInfo class:
@Entity
public class EmployeeInfo {
@Id Integer id;
...
}
Example 3: One-to-one association from an embeddable class to another entity.
@Entity
public class Employee {
@Id int id;
@Embedded LocationDetails location;
...
}
@Embeddable
public class LocationDetails {
int officeNumber;
@OneToOne ParkingSpot parkingSpot;
...
}
@Entity
public class ParkingSpot {
@Id int id;
String garage;
@OneToOne(mappedBy="location.parkingSpot") Employee assignedTo;
...
}
| 修飾子と型 | オプションの要素と説明 |
|---|---|
CascadeType[] | cascade(オプション)関連付けのターゲットにカスケードする必要がある操作。 |
FetchType | fetch(オプション)関連付けを遅延ロードするか、積極的にフェッチする必要があるか。 |
StringSE | mappedBy(オプション)関連を所有するフィールド。 |
boolean | optional(オプション)関連付けがオプションかどうか。 |
boolean | orphanRemoval(オプション)リレーションシップから削除されたエンティティに削除操作を適用し、それらのエンティティに削除操作をカスケードするかどうか。 |
ClassSE | targetEntity(オプション)関連付けのターゲットであるエンティティクラス。 |
public abstract ClassSE targetEntity
デフォルトでは、関連付けを保存するフィールドまたはプロパティの型になります。
public abstract CascadeType[] cascade
デフォルトでは、操作はカスケードされません。
public abstract FetchType fetch
public abstract boolean optional
public abstract StringSE mappedBy
Copyright © 2018,2020 Eclipse Foundation.
Use is subject to license terms.