Roll back A if B goes wrong. spring boot, jdbctemplate

后端 未结 5 749
自闭症患者
自闭症患者 2020-12-23 13:00

I have a method, \'databaseChanges\', which call 2 operations: A, B in iterative way. \'A\' first, \'B\' last. \'A\' & \'B\' can be Create, U

5条回答
  •  萌比男神i
    2020-12-23 13:24

    The first code you present is for UserTransactions, i.e. the application has to do the transaction management. Usually you want the container to take care of that and use the @Transactional annotation. I think the problem in you case might be, that you have the annotation on a private method. I'd move the annotation to the class level

    @Transactional
    public class MyFacade {
    
    public void databaseChanges() throws Exception {   
        A(); //update.
        B(); //insert
    }
    

    Then it should rollback properly. You can find more details here Does Spring @Transactional attribute work on a private method?

提交回复
热议问题