【发布时间】:2023-03-17 22:08:02
【问题描述】:
我正在尝试以“one”作为父级设置双向一对多关系
我有一个父母:
@Entity
public class VideoOnDemand {
@OneToMany(cascade = CascadeType.ALL)
@LazyCollection(LazyCollectionOption.FALSE)
@JoinColumn(name = "video_id")
private List<CuePoint> cuePoints = new ArrayList<CuePoint>();
}
和一个孩子:
@Entity
public class CuePoint {
@ManyToOne(cascade=CascadeType.ALL)
@JoinColumn(name = "video_id", insertable = false, updatable = false)
private VideoOnDemand video;
}
我使用了来自官方 Hibernate documentation (2.2.5.3.1.1) 的建议。但是,Hibernate 似乎不理解 CuePoint 是一个子实体,因此,当我删除 CuePoint 时,它也会删除 VideoOnDemand 以及所有其他 CuePoints。
我做错了什么,正确的方法是什么?
【问题讨论】:
标签: hibernate one-to-many bidirectional