带@EmbeddedId的JPA @OneToMany

时间:2015-10-29 14:26:11

标签: java jpa

我有以下课程(家长):

@Entity
@Table(name = "PROBE_CUSTOMERS")
public class ProbeCustomer implements Serializable {

    private static final long serialVersionUID = 1L;

    private long id;
    private String name;
    private String hostname;
    private List<ProbeMonitor> monitors;

    ....
    @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
    @JoinTable(name = "Probe_Monitors", 
            joinColumns = {@JoinColumn(name = "Df_Customer")})
    @XmlElement(name = "monitors")
    @JsonProperty
    public List<ProbeMonitor> getMonitors() {
        return monitors;
    }
}

列表(类型ProbeMonitor)的@EmbeddedId定义如下:

@Embeddable
public class ProbeMonitorId implements Serializable {

    private static final long serialVersionUID = 1L;

    private String customer;
    private String name;
    private String type;
}

Child类将主键定义为嵌入式ID:

@Entity
@Table(name = "PROBE_MONITORS")
public class ProbeMonitor implements Serializable {

    private static final long serialVersionUID = 1L;

    private ProbeMonitorId id;
    private Integer active;

    @EmbeddedId
    @XmlElement
    @JsonProperty
    public ProbeMonitorId getId() {
        return id;
    }
}

当我创建ProbeCustomer的实体并尝试调用save方法时(使用CrudRepository) 我得到以下(错误的插入语句) - 在插入中有更多的字段,而不是我在那里写的,我已经删除了简洁:

insert into PROBE_CUSTOMERS (Df_Hostname, Dt_Insert, Df_Customer, Dt_Update, id) values (?, ?, ?, ?, ?)
insert into PROBE_MONITORS (Fl_Active, Dt_Insert, Dt_Update, Df_Customer, Df_Monitor, Df_Type) values (?, ?, ?, ?, ?, ?)
insert into Probe_Monitors (Df_Customer, monitors_Df_Customer, monitors_Df_Monitor, monitors_Df_Type) values (?, ?, ?, ?)

我错误地定义了这种关系?

0 个答案:

没有答案
相关问题