我有两个类,我想与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
中的空白答案 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)
您需要执行以下步骤来解决问题
@OneToMany(mappedBy = "pieceEntitie", cascade = CascadeType.ALL, fetch=FetchType.EAGER)
public Set<PieceEntitie> getPieceEntitie() {
return pieceEntitie;
}