0

我有 2 个带有复合键的旧数据库实体,其中一个有一个带有@EmbeddedId注释的复合键。

// 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 回答