Skip to content

JobExecution getJobExecution(@Nullable Long executionId) return null when using MongoDB as JobExplorer #4722

Closed
@weiz-cn

Description

@weiz-cn

Please do a quick search on Github issues first, there might be already a duplicate issue for the one you are about to create.
If the bug is trivial, just go ahead and create the issue. Otherwise, please take a few moments and fill in the following sections:

Bug description
JobExecution getJobExecution(@nullable Long executionId) return null when use MongoDB as JobExplorer

Environment
Java 17, Spring Batch 5.2, MongoDB 4.4.15-15

Steps to reproduce
Steps to reproduce the issue.

Expected behavior
The method should return JobExecution

Minimal Complete Reproducible example
The issue is caused by

org.springframework.batch.core.repository.persistence.JobExecution jobExecution = this.mongoOperations.findById(

From my MongoDB, BATCH_JOB_EXECUTION collection, I saw:

  {
    _id: ObjectId('67486c0b30339b645f463079'),
    jobExecutionId: Long('4'),
    jobInstanceId: Long('4'),

The input argument is the executionId (4), not id (67486c0b30339b645f463079) in MongoDB, the code above use "this.mongoOperations.findById" to find, then nothing is found.
The code should be changed to something like:

Query query = query(where("jobExecutionId").is(executionId);
this.mongoOperations.findOne(query, org.springframework.batch.core.repository.persistence.JobExecution.class,
				JOB_EXECUTIONS_COLLECTION_NAME)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions