删除连接表的行级联休眠
我想从中间连接表中删除数据。我越来越删除连接表的行级联休眠
更新或删除表“eoclass”违反了表“eostaff_user_eoclass” 细节外键约束“fk_o5mbi65xmqv60x0m5v0l1raf8”:密钥(primary_key)=(51)仍然从表“eostaff_user_eoclass”引用。
这里是我的实体
@Entity @Table(name = "EOSTAFF_USER")
@SequenceGenerator(name = "EOSTAFF_USER_SEQ", initialValue = 1, allocationSize = 1, sequenceName = "EOSTAFF_USER_SEQ")
public class EOStaffUser extends EOObject {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "EOSTAFF_USER_SEQ")
@Column(name = "PRIMARY_KEY")
public long primaryKey;
@ManyToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY)
public List<EOClass> eoClassArray = new LinkedList<>();
}
和
@Entity @Table(name = "EOCLASS", uniqueConstraints = @UniqueConstraint(columnNames = { "eoinstitute_primary_key",
"lkclass_primary_key", "lksection_primary_key", "lksubject_primary_key" }))
@SequenceGenerator(name = "EOCLASS_SEQ", initialValue = 1, allocationSize = 1, sequenceName = "EOCLASS_SEQ")
public class EOClass extends EOObject {
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "EOCLASS_SEQ")
@Column(name = "PRIMARY_KEY")
public long primaryKey;
}
回答:
你不能简单地删除EOClass
因为Hibernate不会删除连接表的记录。
对于您的映射,您需要加载EOStaffUser
,从eoClassArray
删除EOclass
并合并整个EOStaffUser
实体。
以上是 删除连接表的行级联休眠 的全部内容, 来源链接: utcz.com/qa/261364.html