使用组合键连接实体

发布于 2024-10-21 19:48:42 字数 733 浏览 10 评论 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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

泪意 2024-10-28 19:48:42

我发现 @MapsId 注释对我的情况有帮助 http:// download.oracle.com/javaee/6/api/javax/persistence/MapsId.html

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文