{"id":20517643,"url":"https://github.com/sovanmukherjee/spring-batch-example","last_synced_at":"2025-03-05T23:41:15.322Z","repository":{"id":190891574,"uuid":"683539388","full_name":"sovanmukherjee/spring-batch-example","owner":"sovanmukherjee","description":"Spring Batch with Spring Boot3 and MySQL DB","archived":false,"fork":false,"pushed_at":"2023-08-30T04:35:19.000Z","size":70,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-16T10:15:45.374Z","etag":null,"topics":["mysql","spring-batch","spring-batch5","springboot3"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/sovanmukherjee.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-08-26T22:30:04.000Z","updated_at":"2024-02-19T07:48:26.000Z","dependencies_parsed_at":null,"dependency_job_id":"1082de20-f635-4a68-b5d5-10530481aa56","html_url":"https://github.com/sovanmukherjee/spring-batch-example","commit_stats":null,"previous_names":["sovanm10/spring-batch-example","sovanmukherjee/spring-batch-example"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sovanmukherjee%2Fspring-batch-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sovanmukherjee%2Fspring-batch-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sovanmukherjee%2Fspring-batch-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sovanmukherjee%2Fspring-batch-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sovanmukherjee","download_url":"https://codeload.github.com/sovanmukherjee/spring-batch-example/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":242123175,"owners_count":20075344,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["mysql","spring-batch","spring-batch5","springboot3"],"created_at":"2024-11-15T21:36:32.343Z","updated_at":"2025-03-05T23:41:15.296Z","avatar_url":"https://github.com/sovanmukherjee.png","language":"Java","readme":"# Spring Batch with Spring Boot3 and MySQL DB\n\n\n###Overview\n\nSpring Batch required following metadata tables to run the job\n\n    |------------------------------|\n    |      Table                   | \n    |------------------------------| \n    | BATCH_JOB_INSTANCE           | \n    | BATCH_JOB_EXECUTION          |\n    | BATCH_JOB_EXECUTION_PARAMS   |\n    | BATCH_STEP_EXECUTION         |\n    | BATCH_JOB_EXECUTION_CONTEXT  |\n    | BATCH_STEP_EXECUTION_CONTEXT |\n    |------------------------------|\n    | BATCH_JOB_EXECUTION_SEQ      |\n    | BATCH_JOB_SEQ                |\n    | BATCH_STEP_EXECUTION_SEQ     |\n    |------------------------------|\n\nWe can use below property in application yml file to create above tables automatically.\n\n`spring.batch.jdbc.initialize-schema: ALWAYS`\n\n\u003cimg width=\"548\" alt=\"image\" src=\"https://github.com/sovanm10/spring-batch-example/assets/26097904/47f76d33-e9e9-4d79-af30-ab2dd5b419ed\"\u003e\n\nIf we want to create the batch metadata tables but not in runtime then we can create them manually\n\n\n#### The BATCH_JOB_INSTANCE Table\nThe BATCH_JOB_INSTANCE table holds all information relevant to a JobInstance.\n\nDDL statement:\n```\nCREATE TABLE BATCH_JOB_INSTANCE  (\n  JOB_INSTANCE_ID BIGINT  PRIMARY KEY ,\n  VERSION BIGINT,\n  JOB_NAME VARCHAR(100) NOT NULL ,\n  JOB_KEY VARCHAR(32) NOT NULL\n);\n```\n#### The BATCH_JOB_EXECUTION Table\nThe BATCH_JOB_EXECUTION table holds all information relevant to the JobExecution object.\n\nDDL statement:\n```\nCREATE TABLE BATCH_JOB_EXECUTION  (\n  JOB_EXECUTION_ID BIGINT  PRIMARY KEY ,\n  VERSION BIGINT,\n  JOB_INSTANCE_ID BIGINT NOT NULL,\n  CREATE_TIME TIMESTAMP NOT NULL,\n  START_TIME TIMESTAMP DEFAULT NULL,\n  END_TIME TIMESTAMP DEFAULT NULL,\n  STATUS VARCHAR(10),\n  EXIT_CODE VARCHAR(20),\n  EXIT_MESSAGE VARCHAR(2500),\n  LAST_UPDATED TIMESTAMP,\n  constraint JOB_INSTANCE_EXECUTION_FK foreign key (JOB_INSTANCE_ID)\n  references BATCH_JOB_INSTANCE(JOB_INSTANCE_ID)\n) ;\n```\n\n#### The BATCH_JOB_EXECUTION_PARAMS Table \nThe BATCH_JOB_EXECUTION_PARAMS table holds all information relevant to the JobParameters object.\n\nDDL statement:\n```\nCREATE TABLE BATCH_JOB_EXECUTION_PARAMS  (\n\tJOB_EXECUTION_ID BIGINT NOT NULL ,\n\tPARAMETER_NAME VARCHAR(100) NOT NULL ,\n\tPARAMETER_TYPE VARCHAR(100) NOT NULL ,\n\tPARAMETER_VALUE VARCHAR(2500) ,\n\tIDENTIFYING CHAR(1) NOT NULL ,\n\tconstraint JOB_EXEC_PARAMS_FK foreign key (JOB_EXECUTION_ID)\n\treferences BATCH_JOB_EXECUTION(JOB_EXECUTION_ID)\n);\n```\n#### The BATCH_STEP_EXECUTION Table\nThe BATCH_STEP_EXECUTION table holds all information relevant to the StepExecution object.\n\nDDL statement:\n``` \nCREATE TABLE BATCH_STEP_EXECUTION  (\n  STEP_EXECUTION_ID BIGINT NOT NULL PRIMARY KEY ,\n  VERSION BIGINT NOT NULL,\n  STEP_NAME VARCHAR(100) NOT NULL,\n  JOB_EXECUTION_ID BIGINT NOT NULL,\n  CREATE_TIME TIMESTAMP NOT NULL,\n  START_TIME TIMESTAMP DEFAULT NULL ,\n  END_TIME TIMESTAMP DEFAULT NULL,\n  STATUS VARCHAR(10),\n  COMMIT_COUNT BIGINT ,\n  READ_COUNT BIGINT ,\n  FILTER_COUNT BIGINT ,\n  WRITE_COUNT BIGINT ,\n  READ_SKIP_COUNT BIGINT ,\n  WRITE_SKIP_COUNT BIGINT ,\n  PROCESS_SKIP_COUNT BIGINT ,\n  ROLLBACK_COUNT BIGINT ,\n  EXIT_CODE VARCHAR(20) ,\n  EXIT_MESSAGE VARCHAR(2500) ,\n  LAST_UPDATED TIMESTAMP,\n  constraint JOB_EXECUTION_STEP_FK foreign key (JOB_EXECUTION_ID)\n  references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID)\n) ;\n```\n#### The BATCH_JOB_EXECUTION_CONTEXT Table\nThe BATCH_JOB_EXECUTION_CONTEXT table holds all information relevant to the ExecutionContext of a Job.\n\nDDL statement:\n```\nCREATE TABLE BATCH_JOB_EXECUTION_CONTEXT  (\n  JOB_EXECUTION_ID BIGINT PRIMARY KEY,\n  SHORT_CONTEXT VARCHAR(2500) NOT NULL,\n  SERIALIZED_CONTEXT CLOB,\n  constraint JOB_EXEC_CTX_FK foreign key (JOB_EXECUTION_ID)\n  references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID)\n) ;\n```\n#### The BATCH_STEP_EXECUTION_CONTEXT Table\nThe BATCH_STEP_EXECUTION_CONTEXT table holds all information relevant to the ExecutionContext of a Step.\n\nDDL statement:\n```\nCREATE TABLE BATCH_STEP_EXECUTION_CONTEXT  (\n  STEP_EXECUTION_ID BIGINT PRIMARY KEY,\n  SHORT_CONTEXT VARCHAR(2500) NOT NULL,\n  SERIALIZED_CONTEXT CLOB,\n  constraint STEP_EXEC_CTX_FK foreign key (STEP_EXECUTION_ID)\n  references BATCH_STEP_EXECUTION(STEP_EXECUTION_ID)\n) ;\n```\n#### Sequence Tables BATCH_JOB_EXECUTION_SEQ, BATCH_JOB_SEQ and BATCH_STEP_EXECUTION_SEQ\nCreate and Insert statements:\n```\nCREATE TABLE BATCH_STEP_EXECUTION_SEQ (ID BIGINT NOT NULL);\nINSERT INTO BATCH_STEP_EXECUTION_SEQ values(0);\n\nCREATE TABLE BATCH_JOB_EXECUTION_SEQ (ID BIGINT NOT NULL);\nINSERT INTO BATCH_JOB_EXECUTION_SEQ values(0);\n\nCREATE TABLE BATCH_JOB_SEQ (ID BIGINT NOT NULL)B;\nINSERT INTO BATCH_JOB_SEQ values(0);\n```\n#### Table used by the application \n* DDL for my_test_db.user\n```\nCREATE TABLE `user` (\n  `id` int NOT NULL,\n  `name` varchar(45) DEFAULT NULL,\n  `roll` varchar(45) DEFAULT NULL,\n  `amount` double DEFAULT NULL,\n  `class_name` varchar(45) NOT NULL,\n  PRIMARY KEY (`id`)\n) \n```\nInsert SQL Script\n```\nINSERT INTO `my_test_db`.`user`\n(`id`,\n`name`,\n`roll`,\n`amount`,\n`class_name`)\nVALUES\n(1, 'Abhi', 1, 100, '1'),\n(2, 'Suman', 2, 200, '1'),\n(3, 'Sandip', 3, 200, '2'),\n(4, 'Sivan', 4, 200, '1');\n\n```\n* Outout\n\u003cimg width=\"1306\" alt=\"Screenshot 2023-08-27 at 4 07 09 AM\" src=\"https://github.com/sovanm10/spring-batch-example/assets/26097904/ac2c2926-5ff5-422d-b344-95f52def3dfc\"\u003e\n\n\n### Reference Documentation\nFor further reference, please consider the following sections:\n\n* [Spring Batch](https://spring.io/projects/spring-batch)\n* [Spring Batch Reference Documentation](https://docs.spring.io/spring-batch/docs/current/reference/html/)  \nThe following guides illustrate how to use some features concretely:\n\n* [Creating a Batch Service](https://spring.io/guides/gs/batch-processing/)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsovanmukherjee%2Fspring-batch-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsovanmukherjee%2Fspring-batch-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsovanmukherjee%2Fspring-batch-example/lists"}