我有一个命名的本机查询,看起来像这样:
@NamedNativeQuery(name = "deleteRecipes", query = "DELETE FROM RECIPE WHERE rcp_acc_identifier IN (?1)")
这些是配方表的重要部分:
Table "public.recipe"
Column | Type | Modifiers
-------------------------+-----------------------------+---------------------------------------------------------
rcp_pf_id_photodata | bigint |
rcp_pf_id_thumbnaildata | bigint |
Indexes:
"fk_rcp_pf_id_photodata_idx" btree (rcp_pf_id_photodata)
"fk_rcp_pf_id_thumbnaildata_idx" btree (rcp_pf_id_thumbnaildata)
Foreign-key constraints:
"fk_rcp_pf_id_photodata" FOREIGN KEY (rcp_pf_id_photodata) REFERENCES persistable_file(pf_id) ON DELETE CASCADE
"fk_rcp_pf_id_thumbnaildata" FOREIGN KEY (rcp_pf_id_thumbnaildata) REFERENCES persistable_file(pf_id) ON DELETE CASCADE
当我执行上面的查询时,配方将被删除,但不会删除persistable_file 中的数据。为什么会这样?附加信息:我在创建数据库时没有设置 ON DELETE CASCADE。我稍后通过首先从上面删除两个约束来添加它,然后我使用附加的 ON DELETE CASCADE 指令再次添加了约束。这可能是为什么数据没有被删除的问题吗?