No rollback only for transaction when exception occurs in submethod

后端 未结 2 1392
心在旅途
心在旅途 2020-12-18 05:39

I\'m using Hibernate + spring + @Transactional annotations to handle transactions in my application.

Transaction manager is declared as follows:

相关标签:
2条回答
  • 2020-12-18 06:09

    You may also need to turn off globalRollbackOnParticipationFailure.

    I had this problem when I had an independent transaction within a surrounding transaction. When the independent transaction failed, it also failed the surrounding transaction.

    Turning off the participation flag solved this for me:

    <bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="globalRollbackOnParticipationFailure" value="false" />
        <property name="sessionFactory" ref="sessionFactory" />
    </bean>
    
    0 讨论(0)
  • 2020-12-18 06:10

    Create another annotation, e.g. @NoRollbackTransactional, something like:

    @Transactional(noRollbackFor = RuntimeException.class)
    public @interface NoRollbackTransactional {
    }
    

    And use this on your methods. On the other hand I agree with Donal's comment, you should revise your transaction scopes, imho it is generally not a good idea to call @Transactional from another @Transactional.

    0 讨论(0)
提交回复
热议问题