Skip to content
Advertisement

@Transactional – rollback on Exception not working

I am using aurora mysql for one of my project, wanted to rollback db update in update2 method in case of any exception.

If I add transaction on update, getting this error Access denied for user ‘root’@’localhost’ (using password: NO). Without transactional annotation, I’m able to perform db operation, there is no issue with credentials.

sudo code:

class operation {
    @Transactional(rollbackFor = Exception.class)
    public void update() {
        update2();
    }
    
    public void update2() {
        dbupdate();
        serverupdate(); >> throws exception.
    }
}

Can someone suggest possible cause? Thanks.

Advertisement

Answer

I found that datasource being used for @Transactional and crud operations were different which was causing issue. for @Transactional default dataSource of application were being used where as for crud, we defined different dataSource.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement