简体   繁体   English

引用主组合键的Hibernate IdClass

[英]Hibernate IdClass referencing a primary composite key

How can I reference a composite primary key in hibernate? 如何在休眠中引用复合主键?

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??
    }
}

Product Vendor Class already has a composite key! 产品供应商类别已具有组合键!

@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

}

You map the ProductVendorPK , as if it were a simple field: 您映射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.

相关问题 具有复合键的自引用实体中的 @ManyToOne - @IdClass、java、hibernate - @ManyToOne in self-referencing entity with composite key - @IdClass, java, hibernate 休眠中使用@idclass的复合键 - composite key using @idclass in hibernate 使用具有3层结构的@IdClass在主键中使用复合键进行JPA 2 Hibernate映射 - JPA 2 Hibernate mapping with composite key in primary key using @IdClass with 3 tier structure Spring Boot Hibernate JPA映射复合主键提供IllegalArgumentException:此类未定义IdClass - Spring Boot Hibernate JPA mapping composite primary key gives IllegalArgumentException: This class does not define an IdClass 如何在springboot hibernate中使用@IdClass在复合主中生成序列ID - how to generate sequence id in composite primary with @IdClass in springboot hibernate 将@IdClass与Hibernate和Arquillian强制CascadeType.Insert一起使用在ManyToOne外键对象上,该对象是实体组合主键的一部分 - Using @IdClass with Hibernate and arquillian force CascadeType.Insert on a ManyToOne foreign key object that is part of entity composite primary key 如何在使用@IdClass复合主键时命名@ForeignKey? - How to name the @ForeignKey when using @IdClass composite primary key? 使用IdClass使用3个主键的Spring JPA数据JPA复合 - Spring jpa data jpa composite with 3 primary key using IdClass 复合主键,使用@IdClass - 列“id”不能是 null - Composite Primary key, using @IdClass - Column 'id' cannot be null Hibernate - 在使用复合主键(@idClass)时,无法在保留其自动生成的属性时插入新记录 - Hibernate - Cannot insert new record when using composite primary key (@idClass), given keeping its auto-generated attribute
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM