OneToMany 与 @EmbeddedId 和 kundera

OneToMany with @EmbeddedId and kundera

我有两个 class,我想使用 OneToMany 与 EmbeddedId 的关系 (我正在使用 kundera 框架) 我的传感器实体 class:

public class SensorEntitie implements Serializable {
    @EmbeddedId
    private CompoundKey key;
    @Column
    private float temperature;
    @Column
    private float pressure;

    @OneToMany(cascade = { CascadeType.ALL }, fetch = FetchType.EAGER)
    @JoinColumn(name="what I should to put here")
    private List<PieceEntitie> pieces;
}
@Embeddable
    public class CompoundKey
    {
        @Column 
        private String IdSensor;           
        @Column 
        private long date;           
        @Column(name = "event_time")
        private long eventTime;

我的作品class实体

public class PieceEntitie implements Serializable{

    /**
     * 
     */
    @Id
    private String IdPiece;
    @Column
    private double width;
    @Column
    private double height;
    @Column
    private double depth;

但是我怎样才能填补@JoinColumn

中的空白

您需要执行以下一些步骤来解决问题

  1. 删除@JoinColumn 你不需要写那个语句
  2. 将@OneToMany 移除到创建的对象
  3. 按照我的以下代码使用 getter 方法绑定 @OneToMany
 @OneToMany(mappedBy = "pieceEntitie", cascade = CascadeType.ALL, 
 fetch=FetchType.EAGER)
    public Set<PieceEntitie> getPieceEntitie() {
            return pieceEntitie; 
    }

我找到了解决方案: 要使用与 EmbeddedId 的 OneToMany 关系,我应该声明 JoinColumnsJoinColumn

的倍数
@OneToMany(cascade = { CascadeType.ALL }, fetch = FetchType.EAGER)
    @JoinColumns({
        @JoinColumn(name = "idsensor", referencedColumnName = "idsensor"),
        @JoinColumn(name = "date", referencedColumnName = "date"),
        @JoinColumn(name = "event_time", referencedColumnName = "event_time")
})