簡體   English   中英

引用主組合鍵的Hibernate IdClass

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM