gpt4 book ai didi

java - 如何在hibernate java中使用where条件删除多条记录

转载 作者:行者123 更新时间:2023-12-02 04:47:39 26 4
gpt4 key购买 nike

我想使用 hibernate 从我的表中删除记录列表:

我的 sql 查询如下所示:

delete from students where joinDate="2014-03-08"

我想删除所有在上述日期加入的记录。

在学生表中,我有两个外键:classId 和 courseId。

您能帮助如何为上述场景编写有效的 hibernate 删除查询方法吗?

感谢您的帮助!

最佳答案

最简单的方法是从每个表中单独删除:

-- Remove all connections from A which reference
-- the B-rows you want to remove
DELETE FROM A_has_B
WHERE B_id IN (1,2);

-- Remove all connections from C which reference
-- the B-rows you want to remove
DELETE FROM C_has_B
WHERE B_id IN (1,2);

-- Finally remove the B-rows
DELETE FROM B
WHERE B_id IN (1,2);

关于java - 如何在hibernate java中使用where条件删除多条记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29530010/

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