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