使用组合键连接实体
我有 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我发现 @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