【发布时间】:2011-08-06 05:18:48
【问题描述】:
如果我有这 3 个实体:
@实体 公共课学生{
@Id @GeneratedValue(strategy=GenerationType.IDENTITY) protected Long id; private String name;}
@实体 @Inheritance(策略=InheritanceType.JOINED) 公开课{
@Id @GeneratedValue(strategy=GenerationType.IDENTITY) protected Long id; @OneToMany private List<Student> students; private String name;}
@实体 @Inheritance(策略=InheritanceType.JOINED) 公共类组 {
@Id @GeneratedValue(strategy=GenerationType.IDENTITY) protected Long id; @OneToMany private List<Student> students; private String name;}
如何使用 JPQL 查询删除学生?
我试试
从学生中删除 WHERE s.name = "John Doe"
但我有
无法删除或更新父行:外键约束失败(database, CONSTRAINT FK_course_student_students_ID FOREIGN KEY (students_ID) REFERENCES student (ID))
为了性能,我需要在纯 JPQL 中执行此操作,我无法执行 entity.remove,因为我有 10000 个 John doe,我需要立即删除它们。
为什么 JPQL 不说:“嘿,让我们从这门生物学课程中删除这个 john doe,他不存在”而不是“嘿,生物学课程非常重要,没有学生可以从这门课程中删除! "
我缺少什么以及我必须使用什么样的注释?
谢谢!
编辑:向 OnToMany 关系添加 @JoinColumn 可能会起作用,除非学生被不同的表引用...
【问题讨论】:
标签: java orm jpa persistence jpql