我有实体ServiceConfig
与OneToMany关系:
@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;
在每个儿童班,我都有:
@ManyToOne(cascade = CascadeType.ALL)
@JoinColumn(name = "TD_SERVICE_CONFIG_ID")
private ServiceConfig serviceConfig;
当我获取新的ServiceConfig
时 - 我有3个表,ServiceConfig
,NotificationItem
和QosItem
。在NotificationItem
和QosItem
表格中,我有空列TD_SERVICE_CONFIG_ID
,但所有数据都已插入。
如何将hibernate(注释或其他配置)配置为成功插入父级id到TD_SERVICE_CONFIG_ID
列的孩子?
答案 0 :(得分:2)
您的配置看起来很好。
我怀疑(虽然显然无法在没有看到您的代码的情况下确定)您没有设置关系的反面,这是必需的。
您可以按如下方式添加NotificationItem
:
NotificationItem item = new NotificationItem();
item.setServiceConfig(service); //set the other side of the bi-directional relationship
servive.getNotificationItems().add(item);
中间线是重要的一条。