![](/img/trans.png)
[英]Spring + Hibernate: creating child mapped to fictional parent in OneToMany relationship
[英]Parent id not insert to child table whit OneToMany relationship in java hibernate
我有與OneToMany關系的實體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;
在每個兒童班,我有:
@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
列?
你的配置看起來很好。
我懷疑(雖然顯然無法確定無法看到你的代碼)你沒有設置關系的反面,這是必需的。 您將添加NotificationItem
,如下所示:
NotificationItem item = new NotificationItem();
item.setServiceConfig(service); //set the other side of the bi-directional relationship
servive.getNotificationItems().add(item);
中間線是重要的一條。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.