2017-05-30 18 views
0

hibernateで複合主キーを参照するにはどうすればよいですか?1次複合キーを参照するHibernate IdClass

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 

} 

答えて

1

それは、単純なフィールドであるかのようにあなたは、ProductVendorPKをマップ:

public static class ProductItemPK implements Serializable { 
    private int itemId; 
    private ProductVendorPK productVendor; 

    // REST OF CLASS AS PER SPECS... 
} 
関連する問題