数据表有
CREATE TABLE review
(
review_id bigint NOT NULL,
review_content character varying(310),
creator_id bigint,
project_date timestamp without time zone,
relationship_id bigint,
project_adress character varying(255),
project_price bigint,
is_confirmed character(255),
state character varying(255),
reference_id bigint,
added_date timestamp without time zone,
edited_date timestamp without time zone,
professional_id bigint,
review_mark bigint,
CONSTRAINT review_pkey PRIMARY KEY (review_id ),
CONSTRAINT fk91b3e37875efd5c1 FOREIGN KEY (relationship_id)
REFERENCES relationship (relationship_id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT fk91b3e3789e7fbcef FOREIGN KEY (creator_id)
REFERENCES member (member_id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT fk91b3e378f069914 FOREIGN KEY (professional_id)
REFERENCES member (member_id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION,
CONSTRAINT fk91b3e378ff77b92 FOREIGN KEY (project_price)
REFERENCES review_project_price (price_id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE NO ACTION
)
的外键。
在model中Review类是这样配置的
@ManyToOne(cascade = CascadeType.DETACH)
@JoinColumn(name = "professional_id")
private Member professional;
可是在删除Member的时候报错
16:10:32,607 WARN JDBCExceptionReporter:233 - SQL Error: 0, SQLState: 23503
16:10:32,607 ERROR JDBCExceptionReporter:234 - 批次处理 0 delete from Member where member_id='40631' 被中止,呼叫 getNextException 以取得原因。
16:10:32,608 WARN JDBCExceptionReporter:233 - SQL Error: 0, SQLState: 23503
16:10:32,608 ERROR JDBCExceptionReporter:234 - 错误: 在 "member" 上的更新或删除操作违反了在 "review" 上的外键约束 "fk91b3e378f069914"
详细:键值对(member_id)=(40631)仍然是从表"review"引用的.
java.sql.BatchUpdateException: 批次处理 0 delete from Member where member_id='40631' 被中止,呼叫 getNextException 以取得原因。
请问各位大牛 这是什么原因?
------解决方案--------------------
cascade=all 直接OK