java引发异常时回滚更改

java引发异常时回滚更改,java,spring,exception,spring-data,spring-batch,Java,Spring,Exception,Spring Data,Spring Batch,在触发电子邮件和更新数据库中的数据之前,我有一个实现(执行一些操作并将对象保存在数据库中) BATCH\u JOB\u EXECUTION\u CONTEXT表 执行此操作时,应用程序正在引发异常。请在下面查找例外情况 2019-10-01 00:00:01,379 [pool-3-thread-1] INFO core.batch.tasklet.RemoveSpringBatchHistoryTasklet: 70 - Remove the Spring Batch histor

在触发电子邮件和更新数据库中的数据之前,我有一个实现(执行一些操作并将对象保存在数据库中)
BATCH\u JOB\u EXECUTION\u CONTEXT

执行此操作时,应用程序正在引发异常。请在下面查找例外情况

    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
即使抛出异常,它也会发送电子邮件和数据库表中更新的错误信息

请在下面找到我的代码

@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.


}

例外从何而来?显示完整的stacktrace。@Andreas-使用完整的stacktrace更新。更好的方法不是将作业监视侦听器添加到作业定义中,然后在侦听器中插入通知程序,以便在作业完成时使用该通知程序发送电子邮件。然后,您还可以在完全知道作业本身没有锁定表的情况下,通过通知程序执行DB工作。。参考:这不是stacktrace,请参阅