spring - Multiple @Transactional annotation over more than 2 methods not working -
i have 2 methods transactions, below
class mytransaction(){ @transactional public void initialtranx(){ string userid = 500; // user specific activity updateuserbalance(500); // check user balance } @transactional private void updateuserbalance(int userid){ // codes updating balance 400 } }
now calling initialtranx() method, method internally calls private method updateuserbalance(userid), balance not getting updated after updateuserbalance method executes. after completing public method(parent method) transaction getting committed.
i need commit second method's transaction, after completing private method itself.
i using mysql db , spring data jpa.
please 1 guide me on this.
@transactional
not work on private methods, use public. depending on class proxy strategy, calling method in same class may not trigger transaction either.jpa not officially support nested transactions. may work spring extent, strange errors can happen.
if want force changes database before transaction committed, can use entitymanager.flush().
Comments
Post a Comment