JpaTransactionManager不回滚事务

时间:2018-07-24 06:37:07

标签: java spring transactions spring-data-jpa jhipster

我使用JHipster制作一个简单的应用程序并编写服务,代码如下:

@Service
@Transactional
public class OperateQueueActionService {
    @Transactional(rollbackFor = Throwable.class)
    public OperateQueueDTO apply(OperateQueueDTO operateQueueDTO, QueueEventType queueEventType, String deskNo) {
    StateMachine<QueueStatus, QueueEventType> stateMachine = operateQueueActionMachineService.getStateMachine();
    try {   QueueEventDTO operateQueueEventDTO = operateQueueUtils.saveQueueEvent(operateQueueDTO, queueEventType, deskNo); 
         ......in process will throw RuntimeException.
        } finally {
           stateMachine.stop();
       }
    }
}

我希望事务回滚而不保存queueEvent,但是记录保存在数据库中。这是事务日志:

  

[2018-07-24 12:04:51.861] [XNIO-2 task-6] WARN o.s.s.l.CompositeStateMachineListener -Error during stateContext java.lang.RuntimeException: 无效状态 at com.higoee.queue.state.utils.OperateQueueStateMachineLogListener.stateContext(OperateQueueStateMachineLogListener.java:58) at java.lang.Thread.run(Thread.java:745) [2018-07-24 12:04:51.871] [XNIO-2 task-6] INFO c.h.q.s.u.OperateQueueStateMachineLogListener -4d667539-3316-491d-a0db-240e29b0fcae状态机状态为:STATEMACHINE_STOP [2018-07-24 12:04:51.872] [XNIO-2 task-6] DEBUG o.s.orm.jpa.JpaTransactionManager -Initiating transaction commit [2018-07-24 12:04:51.874] [XNIO-2 task-6] DEBUG o.s.orm.jpa.JpaTransactionManager -Committing JPA transaction on EntityManager

1 个答案:

答案 0 :(得分:0)

JPA配置没有问题,弹簧状态机已捕获到StateMachineListenerAdapter中引发的异常。