簡體   English   中英

使用Spring數據/休眠進行刪除:ORA-01407:無法更新為Null

[英]Deletions with Spring data/Hibernate: ORA-01407: Cannot update to Null

我正在嘗試使用CRUD存儲庫中deleteAll()方法從數據庫中刪除特定表中的行。

這樣做時,我得到與我的DOG表有關的錯誤,行DOG_OWNER:

ORA-01407: Cannot update DOG_OWNER to Null

修復程序是僅刪除該行上的not-null constraint ,還是有其他解決方法?

在簡化的情況下, FOREIGN KEY不可為ON DELETE SET NULL ,並且使用ON DELETE SET NULL進行約束,這會導致在刪除引用的鍵后導致報告錯誤。

在這種情況下,確實有助於解除外鍵上的NOT NULL約束。

create table dog_owner 
(id number);
alter table dog_owner add  primary key (id);
insert into dog_owner values (1);

create table dog 
(id number,
dog_owner_id number not null); -- foreign key is not nullable ..
alter table dog add  primary key (id);
alter table dog add  foreign key (dog_owner_id) references dog_owner(id) 
ON DELETE SET NULL; -- but the contrains sets is to null...

insert into dog values (1,1);
commit;

delete from dog_owner where id = 1;

-- SQL-Fehler: ORA-01407: cannot update ("SCHEMA_NAME"."DOG"."DOG_OWNER_ID") to NULL 

alter table dog modify (dog_owner_id number  null);

delete from dog_owner where id = 1;

-- 1 rows deleted

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM