0

I am getting exception on update of Hibernate entity, below are the details -

I have created tables partitions as below --case --case_active --case_inactive

---------------Script------------

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();

Exception on update of hibernate entity "Case"(which is mapped to "case" table)-

org.springframework.orm.jpa.JpaOptimisticLockingFailureException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect)

1 Answers1

0

it's relative to your Cascades and your Class Diagram, you are saving some object which cannot be saved by itself.

you should check your cascades and your class diagram, but you can also save them separately for example at first step save the User, and after that set that user to case object and save the case.

Amir Pezeshk
  • 359
  • 1
  • 5