0

As describe in question , where actually transaction get committed in spring desclarative transaction mangament. For e.g suppose i have following code

@Service
@Transactional
class CustomerAService{
    public void processCustomer(Customer customer){
        //call dao and insert customer
        furtherProcessCustomer(Customer customer);
        //last line (a)
    }

    @Transactional(propagation=Propagation.REQUIRES_NEW)
    public void furtherProcessCustomer(Customer customer){
        //call another dao do some db work

        //last line (b)
    }
}

suppose if i stop execution @ line //last line (a) so will trasaction get commited for processCustomer() method. I tried to search on net but didn't get much information

user3608352
  • 397
  • 2
  • 5
  • 15
  • Already answered here: http://stackoverflow.com/questions/12390888/differences-between-requires-new-and-nested-propagation-in-spring-transactions – codependent Jun 20 '14 at 07:43
  • @WornOutSoles although my question was not related to Propagation.REQUIRES_NEW but after reading answer by beerbajay a i am bit confused about the use of Propagation.REQUIRES_NEW . For that ill find some info on net else ask quetion. – user3608352 Jun 20 '14 at 08:41

1 Answers1

0

The transaction management in spring occurs via aspect-oriented-programming (AOP) proxy objects. This means that the method must return cleanly in order for the transaction to be committed. Your code is "Target Method" in the diagram below, while the transactions are committed in the "Transaction Advisor". More documentation here.

AOP transaction processing

Your example is kind of subtle since furtherProcessCustomer method is called from inside the same class, which will not be called via the AOP proxy object and therefore your @Transactional(propagation=Propagation.REQUIRES_NEW) will not be used.

If you had another service, also with @Transactional annotations and then you called furtherProcessCustomer, this would occur via the AOP Proxy object and you would therefore have a nested transaction.

beerbajay
  • 19,652
  • 6
  • 58
  • 75
  • can you give me some url where i can get information about >> furtherProcessCustomer method is called from inside the same class, which will not be called via the AOP proxy object and therefore your @Transactional(propagation=Propagation.REQUIRES_NEW) will not be used – user3608352 Jun 20 '14 at 08:42
  • The Spring doc explains clearly what beerjay pointed out: http://docs.spring.io/spring/docs/3.1.x/spring-framework-reference/html/aop.html#aop-understanding-aop-proxies. Look for this: "However, once the call has finally reached the target object, the SimplePojo reference in this case, any method calls that it may make on itself, such as this.bar() or this.foo(), are going to be invoked against the this reference, and not the proxy" – codependent Jun 20 '14 at 08:50
  • @WornOutSoles thnks ill have a look. – user3608352 Jun 20 '14 at 09:14