hibernate中复杂的复合PrimaryKey继承

时间:2018-06-06 08:44:08

标签: java hibernate jpa inheritance spring-data-jpa

大家好日子,同事们。 我有大量不同的复合主键方案,但它们都有2个公共字段,它们来自根类。

根类:

@Data
@EqualsAndHashCode(callSuper = false)
@AllArgsConstructor
@NoArgsConstructor
@MappedSuperclass
@IdClass(ContentModelPK.class)
public abstract class ContentModel implements Serializable {
    @Id
    private int pointId;
    @Id
    private LocalDate saveDate;
}

根类的主键:

@Data
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode(callSuper = false)
public class ContentModelPK implements Serializable {

    private int pointId;

    private LocalDate saveDate;
}

扩展根类,根类字段的类。主键应该是 (PointId,Date,HouseHoldId)

@Data
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode(callSuper = false)
@IdClass(HouseholdPK.class)
public class Household extends ContentModel {

    @Id
    private Integer householdId;

    private Byte number;

    private Integer originalHouseholdId;

}

HouseHold的主键类:

@Data
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode(callSuper = false)
public class HouseholdPK implements Serializable {

    private Integer householdId;

}

我的问题是: 它会起作用吗? 如何在这种情况下正确扩展? 如果这不是最佳做法,有人可以举例说明如何正确编写它吗?

0 个答案:

没有答案