开发者

Join entity with composite key

I have 2 entities for legacy db with composite keys, one of them has a composite key with @EmbeddedId annotation.

// 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;
 }

How should I define the @OneToOne relation to join as in the following example:

select p.Id, pd.description
from Product p
inner join p.defects pd


I figure out that @MapsId annotation helps in my case http://download.oracle.com/javaee/6/api/javax/persistence/MapsId.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜