使用组合键加入实体 [英] Join entity with composite key

查看:101
本文介绍了使用组合键加入实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

我应该如何定义@OneToOne关系以进行连接,如以下示例所示:

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

推荐答案

我发现@MapsId注释在我的情况下有帮助

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

这篇关于使用组合键加入实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆