【问题标题】:Join entity with composite key使用复合键连接实体
【发布时间】:2011-03-14 23:05:30
【问题描述】:

我有 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

【问题讨论】:

  • 现在我不明白你的问题。您要编写特定的 JPQL 查询吗?
  • JPQL like this select p.Id, pd.description from Products p join f.defects pd

标签: jpa hibernate-annotations


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-01-09
    • 2017-05-25
    • 1970-01-01
    • 1970-01-01
    • 2021-10-10
    • 2015-02-20
    • 2016-09-03
    相关资源
    最近更新 更多