@EmbeddedId
複合キーを持つレガシーデータベース用の2つのエンティティがあり、そのうちの1つには注釈付きの複合キーがあります。
// first entity
@Entity
public class Product {
@Id
private Integer productId;
// lookup table contains code-description pairs
@OneToOne
private ProductDefects defects;
//getters and setters and other code omitted
}
// lookup entity
@Entity
public class ProductDefects {
@EmbededId
private ProductDefectsPK id;
//getters and setters and other code omitted
}
//composite key
@Embedable
public class ProductDefectsPk{
private Integer realId;
private String category;
}
@OneToOne
次の例のように、結合する関係をどのように定義する必要がありますか。
select p.Id, pd.description
from Product p
inner join p.defects pd