Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jpa 使用复合键连接实体_Jpa_Hibernate Annotations - Fatal编程技术网

Jpa 使用复合键连接实体

Jpa 使用复合键连接实体,jpa,hibernate-annotations,Jpa,Hibernate Annotations,我有两个具有复合键的遗留db实体,其中一个具有带有@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 othe

我有两个具有复合键的遗留db实体,其中一个具有带有
@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

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

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

现在我不明白你的问题。你想写一个特定的JPQL查询吗?像这样的JPQL选择p.Id,pd.description from Products p join f.defects pdNow我不理解你的问题。您想编写一个特定的JPQL查询吗?像这样的JPQL从产品中选择p.Id,pd.description p join f.defects pd