在java hibernate中,父id未插入到具有OneToMany关系的子表中

在java hibernate中,父id未插入到具有OneToMany关系的子表中,java,hibernate,jpa,Java,Hibernate,Jpa,我有实体ServiceConfig与一家公司的关系: @OneToMany(mappedBy = "serviceConfig", fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true) private List<NotificationItem> notificationItems; @OneToMany(mappedBy = "serviceConfig", fe

我有实体
ServiceConfig
与一家公司的关系:

    @OneToMany(mappedBy = "serviceConfig", fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
    private List<NotificationItem> notificationItems;

    @OneToMany(mappedBy = "serviceConfig", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
    private List<QosItem> qosItems;
当我获取新的
ServiceConfig
-我有3个表,
ServiceConfig
NotificationItem
QosItem
。在
NotificationItem
QosItem
表中,我有空列
TD\u SERVICE\u CONFIG\u ID
,但插入了所有数据


如何配置hibernate(注释或其他配置)以成功地将父id插入子id的
TD\u SERVICE\u config\u id
列?

您的配置看起来很好

我怀疑(虽然在没有看到代码的情况下显然无法确定)您没有设置关系的反面,这是必需的。 您将添加一个
NotificationItem
,如下所示:

NotificationItem item = new NotificationItem();
item.setServiceConfig(service);  //set the other side of the bi-directional relationship
servive.getNotificationItems().add(item);

中间一行是这里最重要的一行。

如何保存实体?!您是否为两个NotificationItem和QosItem设置ServiceConfig?!您好,我尝试了上述方法,但在数据库中插入了两个条目,而不是一个条目。
NotificationItem item = new NotificationItem();
item.setServiceConfig(service);  //set the other side of the bi-directional relationship
servive.getNotificationItems().add(item);