OneToMany与@EmbeddedId和kundera

时间:2016-05-11 12:05:13

标签: java hibernate cassandra kundera

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

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;

我的作品类实体

public class PieceEntitie implements Serializable{

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

但我如何填写@JoinColumn

中的空白

2 个答案:

答案 0 :(得分:4)

我找到了解决方案: 要使用与EmbeddedId的OneToMany关系,我应该声明 JoinColumns 和多个 JoinColumn

@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")
})

答案 1 :(得分:1)

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

  1. 删除@JoinColumn,您不需要编写该声明
  2. 将@OneToMany移除到创建的对象
  3. 根据以下代码
  4. 使用getter方法绑定@OneToMany
     @OneToMany(mappedBy = "pieceEntitie", cascade = CascadeType.ALL, 
     fetch=FetchType.EAGER)
    
        public Set<PieceEntitie> getPieceEntitie() {
                return pieceEntitie; 
        }