spring-batch icon indicating copy to clipboard operation
spring-batch copied to clipboard

Batch job fails when using specific schema in PostgreSQL

Open grey-scaven opened this issue 3 years ago • 0 comments

Bug description A problem occurs when defining and using meta tables in a specific schema of PostgreSQL. I used SQL for metatables included in spring batch core. (ex. org/springframework/batch/core/schema-postgresql.sql)

Environment Spring Batch 4.3.5 Java 11 PostgreSQL 12 and metatables on specific schema

Steps to reproduce

  1. Create spring batch metatables on specific schema (ex. item)
CREATE TABLE item.BATCH_JOB_INSTANCE (
	JOB_INSTANCE_ID BIGINT NOT NULL PRIMARY KEY DEFAULT nextval('item.BATCH_JOB_SEQ'),
	VERSION BIGINT,
	JOB_NAME VARCHAR NOT NULL,
	JOB_KEY VARCHAR NOT NULL,
	constraint JOB_INST_UN unique (JOB_NAME, JOB_KEY)
);

  1. Running batch until 30 times
  2. An error occurs and aborted as below
Caused by: org.postgresql.util.PSQLException: ERROR: insert or update on table "batch_job_execution" violates foreign key constraint "job_inst_exec_fk"
  Detail: Key (job_instance_id)=(30) is not present in table "batch_job_instance".

Expected behavior Batch job doesn't fail because of invalid foreign key constraint.

grey-scaven avatar Apr 25 '22 15:04 grey-scaven