我在更新 Hibernate 实体时遇到异常,以下是详细信息 -
我创建了如下表分区
--case
--case_active
--case_inactive
- - - - - - - -脚本 - - - - - -
CREATE TABLE user_active (
CHECK (case_state <>'CLOSED')
) INHERITS (case);
CREATE TABLE case_inactive (
CHECK (case_state ='CLOSED')
) INHERITS (case);
------------ Update Triggers-------------
-- Trigger for - active case (closing) -- Move record from active_case to inactive_case
CREATE OR REPLACE FUNCTION active_case_partition_trigger_fn()
RETURNS TRIGGER AS $$
BEGIN
IF (NEW.case_state = 'CLOSED' ) THEN
INSERT INTO case_inactive VALUES (NEW.*);
DELETE FROM case_active WHERE case_id = NEW.case_id;
--RETURN NULL;
END IF;
RETURN NEW;
END;
$$
LANGUAGE plpgsql;
CREATE TRIGGER active_case_partition_trigger
BEFORE UPDATE ON case_active
FOR EACH ROW EXECUTE PROCEDURE active_case_partition_trigger_fn();
-- Trigger for - Inactive case (Reopening) -- Move record from inactive_case to active_case
CREATE OR REPLACE FUNCTION inactive_case_partition_trigger_fn()
RETURNS TRIGGER AS $$
BEGIN
IF (NEW.case_state <> 'CLOSED') THEN
INSERT INTO case_active VALUES (NEW.*);
DELETE FROM case_inactive WHERE case_id = NEW.case_id;
update movement set active = true where document_id = new.case_id;
--RETURN NULL;
END IF;
RETURN NEW;
END;
$$
LANGUAGE plpgsql;
CREATE TRIGGER inactive_case_partition_trigger
BEFORE UPDATE ON case_inactive
FOR EACH ROW EXECUTE PROCEDURE inactive_case_partition_trigger_fn();
更新休眠实体“案例”(映射到“案例”表)的异常 -
org.springframework.orm.jpa.JpaOptimisticLockingFailureException:行已被另一个事务更新或删除(或未保存值映射不正确)