Transaction marked as rollback only: How do I find the cause

后端 未结 8 1638
深忆病人
深忆病人 2020-11-28 19:39

I am having issues with committing a transaction within my @Transactional method:

methodA() {
    methodB()
}

@Transactional
methodB() {
    ...
    em.pers         


        
相关标签:
8条回答
  • 2020-11-28 20:15

    To quickly fetch the causing exception without the need to re-code or rebuild, set a breakpoint on

    org.hibernate.ejb.TransactionImpl.setRollbackOnly() // Hibernate < 4.3, or
    org.hibernate.jpa.internal.TransactionImpl() // as of Hibernate 4.3
    

    and go up in the stack, usually to some Interceptor. There you can read the causing exception from some catch block.

    0 讨论(0)
  • 2020-11-28 20:17

    When you mark your method as @Transactional, occurrence of any exception inside your method will mark the surrounding TX as roll-back only (even if you catch them). You can use other attributes of @Transactional annotation to prevent it of rolling back like:

    @Transactional(rollbackFor=MyException.class, noRollbackFor=MyException2.class)
    
    0 讨论(0)
提交回复
热议问题