404 ページの「Java Persistence 2.0、最終リリース」には、次の例があります。
例 3: 埋め込み可能なクラスから別のエンティティへの 1 対 1 の関連付け。
@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;
...
}
Employee 内に複数の LocationDetails が必要です。
@Entity
public class Employee {
@Id int id;
@ElementCollection
@CollectionTable(name="EMP_LOCATION")
Map<String, LocationDetails> locations;
...
}
コレクション テーブル EMP_LOCATION 内の埋め込み可能な LocationDetails を指すようにエンティティ ParkingSpot を変更する方法。
する必要があります
@OneToOne(mappedBy="location.parkingSpot") Employee assignedTo;
@ElementCollection に置き換えられますか?
ありがとう!