h.zak h.zak - 5 months ago 19
Java Question

OneToMany with @EmbeddedId and kundera

I have two class and I want to use OneToMany relation with EmbeddedId
(Im working with kundera framework)
my sensor entity class:

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

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

my piece class entity

public class PieceEntitie implements Serializable{

private String IdPiece;
private double width;
private double height;
private double depth;

but how can i fill the blank in @JoinColumn


I found the solution : to use OneToMany relation with EmbeddedId, I should to declare JoinColumns and multiple of JoinColumn

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