![](/img/trans.png)
[英]@ManyToOne in self-referencing entity with composite key - @IdClass, java, hibernate
[英]Hibernate IdClass referencing a primary composite key
如何在休眠中引用复合主键?
IdClass(ProductItem.ProductItemPK.class)
public class ProductItem implements Serializable{
@Id
@Column(name="ITEM_ID")
private int itemId;
@Id
@JoinColumns({
@JoinColumn(name="VENDOR_ID", referencedColumnName="VENDOR_ID"),
@JoinColumn(name="ORDER_ID", referencedColumnName="ORDER_ID")
})
@ManyToOne
private ProductVendor productVendor;
public static class ProductItemPK implements Serializable{
//How to reference ids??
}
}
产品供应商类别已具有组合键!
@IdClass(ProductVendor.ProductVendorPK.class)
public class ProductVendor implements Serializable{
@Id
@JoinColumn(name="VENDOR_ID")
@ManyToOne
private Vendor vendor;
@Id
@JoinColumn(name="ORDER_ID")
@ManyToOne
private Order order;
public static class ProductVendorPK implements Serializable{
protected int vendor;
protected long order;
//equals and hashCode
}
您映射ProductVendorPK
,就好像它是一个简单字段一样:
public static class ProductItemPK implements Serializable {
private int itemId;
private ProductVendorPK productVendor;
// REST OF CLASS AS PER SPECS...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.