Hibernate (Spring JPA): @ManyToOne JoinColumns (这是一个 EmbeddedId) 为空

Hibernate (Spring JPA): @ManyToOne JoinColumns (which are an EmbeddedId) are null

我没有看到我的错误,在对 Whosebug 和 Google 进行研究后,我认为代码应该是正确的。但是 Hibernate (spring-boot-starter-data-jpa 2.2.4) 仍然用 null.

填充 JoinColumns

这是我的 OneToMany class:

@Entity
@Table(name = "tablea", schema = "")
public class TableAEntity implements Serializable {

    private static final long serialVersionUID = 7890327260188587351L;

    @EmbeddedId
    private MyId id;
    
    @OneToMany(cascade = ALL, mappedBy = "tableA", orphanRemoval = true, fetch = FetchType.LAZY)
    private List<TableBEntity> tableBentries;
    
    // Getter + Setter
}

我的EmbeddedIdclass:

@Embeddable
public class MyId implements Serializable {

    private static final long serialVersionUID = -8267953052238233498L;

    @Column(name = "id")
    private String id;

    @Column(name = "iddate")
    private Date iddate;

    @Column(name = "idint")
    private BigInteger idint;
    
    // Getter + Setter
}

最后是我的 ManyToOne class:

@Entity
@Table(name = "tableB", schema = "")
public class TableBEntity implements Serializable {

    private static final long serialVersionUID = -4648090658471459969L;

    @Id
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumns({
        @JoinColumn(name = "id", referencedColumnName = "id"),
        @JoinColumn(name = "iddate", referencedColumnName = "iddate"),
        @JoinColumn(name = "idint", referencedColumnName = "idint")
    })
    private TableAEntity tableA;
    
    // Some other attributes
    
    // Getter + Setter
}

如您所见,我想将属性(ididdateidint)用作两个表中的组合主键。

当我创建 TableAEntity 对象时,我将几个 TableBEntity 对象添加到 tableBentries 属性。对于每个 TableBEntity,我都将引用设置为 TableAEntity(属性 tableA)。当然还有MyId(属性id)对象被填充了。

保存 TableAEntity 对象后,Hibernate 还存储了所有 TableBEntity 但字段 ididdateidint(所有 JoinColumn 的)是 null.

有什么想法吗?

我的 TableBEntity 中的 @Id 似乎是问题所在。如果我将它移到另一个属性,它会起作用。