Encountered fatal error executing joborg.springframework.dao.EmptyResultDataAccessException: Incorrect result size: expected 1, actual 0

11/27/2019

While executing

private static final String CURRENT_VERSION_JOB_EXECUTION = "SELECT VERSION FROM %PREFIX%JOB_EXECUTION WHERE JOB_EXECUTION_ID=?";

by spring (it is already written in JdbcJobExecutionDao) i am gettting this error

Encountered fatal error executing joborg.springframework.dao.EmptyResultDataAccessException: Incorrect result size: expected 1, actual 0

it is not able to get record from batch_job_execution table but record is present in table. my app is running on kubernetes and i m getting this error from kubernetes but not from my local code.

-- Ashish Kumar
java
kubernetes
spring
spring-batch
spring-boot

1 Answer

11/27/2019

According to the documentation

Data access exception thrown when a result was expected to have at least one row (or element) but zero rows (or elements) were actually returned.

You can approach this in few ways:

  1. Modify your query to always return 1 result.

  2. Catch the exception and apply a behavior that you find fit. For example you can check this guide and use it as an example.

  3. Use query method instead to avoid this exception.

Please let me know if that helped.

-- OhHiMark
Source: StackOverflow