I've encountered a couple of problems with the spring-batch-schema-mysql.sql definition:
- Looks like TIMESTAMP in mysql will cannot be set to null by default (see http://dev.mysql.com/doc/refman/5.1/en/timestamp.html).
So without the NULL qualifier M5 definitions of JOB_EXECUTION and STEP_EXECUTION END_TIME will always be populated.
One consequence of this is that Job will always have an END_TIME and JobExecution.isRunning() will always return false.
- Secondly the foreign key constraints fail due to type differences on ID columns (BIGINT unsigned vs BIGINT).
So Definition 1. below fails with:
SQL state [HY000]; error code [1005]; Can't create table '.\dml\batch_job_execution.frm' (errno: 150); nested exception is java.sql.SQLException: Can't create table '.\dml\batch_job_execution.frm' (errno: 150)
Defintion 2. appears to work and supports the NULL END_TIME requirement
Code:
CREATE TABLE BATCH_JOB_EXECUTION (
JOB_EXECUTION_ID BIGINT unsigned PRIMARY KEY ,
VERSION BIGINT,
JOB_INSTANCE_ID BIGINT NOT NULL,
START_TIME TIMESTAMP,
END_TIME TIMESTAMP ,
STATUS VARCHAR(10),
CONTINUABLE CHAR(1),
EXIT_CODE VARCHAR(20),
EXIT_MESSAGE VARCHAR(2500),
constraint JOB_INSTANCE_EXECUTION_FK foreign key(JOB_INSTANCE_ID)
references BATCH_JOB_INSTANCE(JOB_INSTANCE_ID)
);
Code:
CREATE TABLE BATCH_JOB_EXECUTION (
JOB_EXECUTION_ID BIGINT unsigned PRIMARY KEY ,
VERSION BIGINT,
JOB_INSTANCE_ID BIGINT unsigned NOT NULL, // added unsigned
START_TIME TIMESTAMP,
END_TIME TIMESTAMP NULL, // added NULL
STATUS VARCHAR(10),
CONTINUABLE CHAR(1),
EXIT_CODE VARCHAR(20),
EXIT_MESSAGE VARCHAR(2500),
constraint JOB_INSTANCE_EXECUTION_FK foreign key (JOB_INSTANCE_ID)
references BATCH_JOB_INSTANCE(JOB_INSTANCE_ID)
);