gpt4 book ai didi

java - ORA-02292 : integrity constraint violated - child record found - fetchType issue?

转载 作者:行者123 更新时间:2023-11-30 05:43:48 30 4
gpt4 key购买 nike

从具有多个子实体的表中删除时遇到一个小问题。

我有一张名为 UNIVERSITY 的表和一张名为 STUDENT 的表。

@OneToMany(mappedBy = "university", fetch = FetchType.EAGER, cascade = CascadeType.ALL, orphanRemoval = true)
private List<Student> studentList = new ArrayList<>();

@ManyToOne(fetch = FetchType.EAGER)
private University university;

我希望从大学表中删除一行:

@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public void deleteFromUniveristy(Long id) {
em.createNamedQuery(University.DELETE_BY_ID)
.setParameter("id", id)
.executeUpdate();
}

@NamedQuery(name = University.DELETE_BY_ID, query = "delete from University uu where uu.id =:id")

但是收到错误消息:

java.sql.SQLIntegrityConstraintViolationException: ORA-02292: integrity constraint violated - child record found

我不明白,orphanRemoval = true 并且给定的 CascadeType 不能保证可以进行此删除?

谢谢!

最佳答案

可以使用 entityManager.remove(entity) 方法删除父级和子级。级联在删除 JPQL 中不起作用。

关于java - ORA-02292 : integrity constraint violated - child record found - fetchType issue?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55189512/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com