I have an implementation ( doing some operations and save the object in database ) before its triggering an email and update data in
BATCH_JOB_EXECUTION_CONTEXT
table.
While do this operation application is throwing an exception. Please find the exception below.
2019-10-01 00:00:01,379 [pool-3-thread-1] INFO core.batch.tasklet.RemoveSpringBatchHistoryTasklet: 70 - Remove the Spring Batch history before the 9/1/19 12:00 AM
2019-10-01 00:00:19,082 [pool-3-thread-1] INFO core.batch.tasklet.RemoveSpringBatchHistoryTasklet: 73 - Deleted rows number from the BATCH_STEP_EXECUTION_CONTEXT table: 1293132
2019-10-01 00:01:17,216 [pool-3-thread-1] INFO core.batch.tasklet.RemoveSpringBatchHistoryTasklet: 77 - Deleted rows number from the BATCH_STEP_EXECUTION table: 1293132
2019-10-01 00:01:26,461 [pool-3-thread-1] INFO core.batch.tasklet.RemoveSpringBatchHistoryTasklet: 81 - Deleted rows number from the BATCH_JOB_EXECUTION_CONTEXT table: 1295359
2019-10-01 00:03:20,615 [WebContainer-9] ERROR com.api.controller.BaseController: 82 - Unhandled exception while processing request for URL : https://scsbatch.com:9152/jobs/emails with exception : PreparedStatementCallback; SQL [INSERT INTO BATCH_JOB_EXECUTION_CONTEXT (SHORT_CONTEXT, SERIALIZED_CONTEXT, JOB_EXECUTION_ID) VALUES(?, ?, ?)]; Lock wait timeout exceeded; try restarting transaction; nested exception is java.sql.SQLException: Lock wait timeout exceeded; try restarting transaction
org.springframework.dao.CannotAcquireLockException: PreparedStatementCallback; SQL [INSERT INTO BATCH_JOB_EXECUTION_CONTEXT (SHORT_CONTEXT, SERIALIZED_CONTEXT, JOB_EXECUTION_ID) VALUES(?, ?, ?)]; Lock wait timeout exceeded; try restarting transaction; nested exception is java.sql.SQLException: Lock wait timeout exceeded; try restarting transaction
Eventhough its throwing an exception it sends email and wrong information updated in the database table.
Please find my code below.
@Override
@Transactional
public void approve(Long id, ClaimApproval claimApproval) {
Claim claim = claimRepository.findOne(id);
ClaimAssignment claimAssignment = claim.findNextPendingAssignment();
claim.incrementApprovalLevel();
claim.addHistory(historyRecordFor(claimApproval, HistoryAction.APPROVED));
claimRepository.save(claim);
if (!areAllAssignmentsApproved(claim))
emailDispatcherService.notifyNextClaimApprover(claim, assignmentService.getNextLevelApprovers(claim)); //Exception is throws here, but previous statements are executed properly and that should not happen when exception thrown.
}