今天本来是想试一下springbatch看下各个表中都会保存什么内容,结果我就把九张表中所有的内容都删了,然后重新跑批结果又一个坑,报错:
org.springframework.dao.DuplicateKeyException: PreparedStatementCallback; SQL [INSERT into BATCH_JOB_INSTANCE(JOB_INSTANCE_ID, JOB_NAME, JOB_KEY, VERSION) values (?, ?, ?, ?)]; Duplicate entry '0' for key 'PRIMARY'; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '0' for key 'PRIMARY'
后来又是一顿百度啊,结果是那三个以_seq结尾的表中不能为空有初始化内容
(本人已验证)正确的初始化脚本信息为:
1 -- Autogenerated: do not edit this file
2
3 CREATE TABLE BATCH_JOB_INSTANCE (
4 JOB_INSTANCE_ID BIGINT NOT NULL PRIMARY KEY ,
5 VERSION BIGINT ,
6 JOB_NAME VARCHAR(100) NOT NULL,
7 JOB_KEY VARCHAR(32) NOT NULL,
8 constraint JOB_INST_UN unique (JOB_NAME, JOB_KEY)
9 ) ENGINE=InnoDB;
10
11 CREATE TABLE BATCH_JOB_EXECUTION (
12 JOB_EXECUTION_ID BIGINT NOT NULL PRIMARY KEY ,
13 VERSION BIGINT ,
14 JOB_INSTANCE_ID BIGINT NOT NULL,
15 CREATE_TIME DATETIME NOT NULL,
16 START_TIME DATETIME DEFAULT NULL ,
17 END_TIME DATETIME DEFAULT NULL ,
18 STATUS VARCHAR(10) ,
19 EXIT_CODE VARCHAR(2500) ,
20 EXIT_MESSAGE VARCHAR(2500) ,
21 LAST_UPDATED DATETIME,
22 JOB_CONFIGURATION_LOCATION VARCHAR(2500) NULL,
23 constraint JOB_INST_EXEC_FK foreign key (JOB_INSTANCE_ID)
24 references BATCH_JOB_INSTANCE(JOB_INSTANCE_ID)
25 ) ENGINE=InnoDB;
26
27 CREATE TABLE BATCH_JOB_EXECUTION_PARAMS (
28 JOB_EXECUTION_ID BIGINT NOT NULL ,
29 TYPE_CD VARCHAR(6) NOT NULL ,
30 KEY_NAME VARCHAR(100) NOT NULL ,
31 STRING_VAL VARCHAR(250) ,
32 DATE_VAL DATETIME DEFAULT NULL ,
33 LONG_VAL BIGINT ,
34 DOUBLE_VAL DOUBLE PRECISION ,
35 IDENTIFYING CHAR(1) NOT NULL ,
36 constraint JOB_EXEC_PARAMS_FK foreign key (JOB_EXECUTION_ID)
37 references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID)
38 ) ENGINE=InnoDB;
39
40 CREATE TABLE BATCH_STEP_EXECUTION (
41 STEP_EXECUTION_ID BIGINT NOT NULL PRIMARY KEY ,
42 VERSION BIGINT NOT NULL,
43 STEP_NAME VARCHAR(100) NOT NULL,
44 JOB_EXECUTION_ID BIGINT NOT NULL,
45 START_TIME DATETIME NOT NULL ,
46 END_TIME DATETIME DEFAULT NULL ,
47 STATUS VARCHAR(10) ,
48 COMMIT_COUNT BIGINT ,
49 READ_COUNT BIGINT ,
50 FILTER_COUNT BIGINT ,
51 WRITE_COUNT BIGINT ,
52 READ_SKIP_COUNT BIGINT ,
53 WRITE_SKIP_COUNT BIGINT ,
54 PROCESS_SKIP_COUNT BIGINT ,
55 ROLLBACK_COUNT BIGINT ,
56 EXIT_CODE VARCHAR(2500) ,
57 EXIT_MESSAGE VARCHAR(2500) ,
58 LAST_UPDATED DATETIME,
59 constraint JOB_EXEC_STEP_FK foreign key (JOB_EXECUTION_ID)
60 references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID)
61 ) ENGINE=InnoDB;
62
63 CREATE TABLE BATCH_STEP_EXECUTION_CONTEXT (
64 STEP_EXECUTION_ID BIGINT NOT NULL PRIMARY KEY,
65 SHORT_CONTEXT VARCHAR(2500) NOT NULL,
66 SERIALIZED_CONTEXT TEXT ,
67 constraint STEP_EXEC_CTX_FK foreign key (STEP_EXECUTION_ID)
68 references BATCH_STEP_EXECUTION(STEP_EXECUTION_ID)
69 ) ENGINE=InnoDB;
70
71 CREATE TABLE BATCH_JOB_EXECUTION_CONTEXT (
72 JOB_EXECUTION_ID BIGINT NOT NULL PRIMARY KEY,
73 SHORT_CONTEXT VARCHAR(2500) NOT NULL,
74 SERIALIZED_CONTEXT TEXT ,
75 constraint JOB_EXEC_CTX_FK foreign key (JOB_EXECUTION_ID)
76 references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID)
77 ) ENGINE=InnoDB;
78
79 CREATE TABLE BATCH_STEP_EXECUTION_SEQ (
80 ID BIGINT NOT NULL,
81 UNIQUE_KEY CHAR(1) NOT NULL,
82 constraint UNIQUE_KEY_UN unique (UNIQUE_KEY)
83 ) ENGINE=InnoDB;
84
85 INSERT INTO BATCH_STEP_EXECUTION_SEQ (ID, UNIQUE_KEY) select * from (select 0 as ID, '0' as UNIQUE_KEY) as tmp where not exists(select * from BATCH_STEP_EXECUTION_SEQ);
86
87 CREATE TABLE BATCH_JOB_EXECUTION_SEQ (
88 ID BIGINT NOT NULL,
89 UNIQUE_KEY CHAR(1) NOT NULL,
90 constraint UNIQUE_KEY_UN unique (UNIQUE_KEY)
91 ) ENGINE=InnoDB;
92
93 INSERT INTO BATCH_JOB_EXECUTION_SEQ (ID, UNIQUE_KEY) select * from (select 0 as ID, '0' as UNIQUE_KEY) as tmp where not exists(select * from BATCH_JOB_EXECUTION_SEQ);
94
95 CREATE TABLE BATCH_JOB_SEQ (
96 ID BIGINT NOT NULL,
97 UNIQUE_KEY CHAR(1) NOT NULL,
98 constraint UNIQUE_KEY_UN unique (UNIQUE_KEY)
99 ) ENGINE=InnoDB;
100
101 INSERT INTO BATCH_JOB_SEQ (ID, UNIQUE_KEY) select * from (select 0 as ID, '0' as UNIQUE_KEY) as tmp where not exists(select * from BATCH_JOB_SEQ);