OneToMany with @EmbeddedId and kundera

半城伤御伤魂 提交于 2021-01-27 13:42:00

问题


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


回答1:


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



回答2:


You need to do some following steps for fixing problem

  1. Remove @JoinColumn you dont need to write that statement
  2. Remove @OneToMany to created object
  3. Bind @OneToMany with getter method as per my following code
 @OneToMany(mappedBy = "pieceEntitie", cascade = CascadeType.ALL, 
 fetch=FetchType.EAGER)
    public Set<PieceEntitie> getPieceEntitie() {
            return pieceEntitie; 
    }


来源:https://stackoverflow.com/questions/37162156/onetomany-with-embeddedid-and-kundera

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!