我正在尝试更新与另一个表具有多对多关系的实体。
@Entity(name = "coaching")
public class CoachingEntity {
@ManyToMany(fetch = FetchType.LAZY, cascade = { CascadeType.REFRESH })
@JoinTable(name = "coaching_field", joinColumns = @JoinColumn(name = "coachingId", referencedColumnName = "coachingId"), inverseJoinColumns = @JoinColumn(name = "fieldId", referencedColumnName = "fieldId"))
private Set<FieldEntity> fieldEntityList;
现在,当我更新 CoachingEntity 时,hibernate 正在从 coaching_field 表(多对多连接表)中删除条目。我在互联网上搜索过(JPA 更新多对多删除记录),但我找不到正确的方法。即使在JPA 中,所有者触发器上的多对多合并在联接表上删除,我也尝试了他推荐的方法,他使用了 set,但我面临同样的问题。根据https://stackoverflow.com/a/1078295/2116229,我是否需要覆盖等于和哈希码?