0

我在更新 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:行已被另一个事务更新或删除(或未保存值映射不正确)

4

1 回答 1

0

它与您的级联和类图相关,您正在保存一些无法自行保存的对象。

您应该检查您的级联和类图,但您也可以单独保存它们,例如在第一步保存用户,然后将该用户设置为案例对象并保存案例。

于 2020-04-13T11:16:21.570 回答