Could not commit JPA transaction: Transaction marked as rollbackOnly

前端 未结 5 1612
不知归路
不知归路 2020-11-30 21:45

I\'m using Spring and Hibernate in one of the applications that I\'m working on and I\'ve got a problem with handling of transactions.

I\'ve got a service class that

5条回答
  •  天命终不由人
    2020-11-30 22:45

    For those who can't (or don't want to) setup a debugger to track down the original exception which was causing the rollback-flag to get set, you can just add a bunch of debug statements throughout your code to find the lines of code which trigger the rollback-only flag:

    logger.debug("Is rollbackOnly: " + TransactionAspectSupport.currentTransactionStatus().isRollbackOnly());
    

    Adding this throughout the code allowed me to narrow down the root cause, by numbering the debug statements and looking to see where the above method goes from returning "false" to "true".

提交回复
热议问题