Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 {
    @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;

my piece class entity

public class PieceEntitie implements Serializable{

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

but how can i fill the blank in @JoinColumn

like image 366
h.zak Avatar asked Dec 18 '22 17:12

h.zak


1 Answers

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)
    @JoinColumns({
        @JoinColumn(name = "idsensor", referencedColumnName = "idsensor"),
        @JoinColumn(name = "date", referencedColumnName = "date"),
        @JoinColumn(name = "event_time", referencedColumnName = "event_time")
})
like image 99
h.zak Avatar answered Jan 02 '23 11:01

h.zak