0

@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
4

1 に答える 1

3

私の場合、@MapsIdアノテーションが役立つことがわかりましたhttp://download.oracle.com/javaee/6/api/javax/persistence/MapsId.html

于 2011-03-15T19:16:13.037 に答える