Read in and out of these three links:

http://docs.spring.io/spring/docs/2.5.x/reference/transaction.html

http://docs.spring.io/spring/docs/2.5.x/reference/transaction.html#transaction-declarative

http://docs.spring.io/spring/docs/2.5.x/reference/transaction.html#transaction-programmatic

 

Some highlights on declarative transaction management.

You annotate your classes with the @Transactional annotation, add the line ('<tx:annotation-driven/>') to your configuration, and then expect you to understand how it all works.

The most important concepts to grasp with regard to the Spring Framework’s declarative transaction support are that

  • this support is enabled via AOP proxies, and that
  • the transactional advice is driven by metadata (currently XML- or annotation-based).
  • The combination of AOP with transactional metadata yields an AOP proxy that uses a TransactionInterceptor in conjunction with an appropriate PlatformTransactionManager implementation to drive transactions around method invocations.

Spring AOP, comes with three technical terms – Advices, Pointcut , Advisor,

  • Advice“what action” Indicate the action to take either before or after the method execution.
  • Pointcut – Indicate “which method should be intercepted”, by method name or regular expression pattern.
  • AdvisorGroup ‘Advice’ and ‘Pointcut’ into a single unit, and pass it to a proxy factory object.

<aop:config> – The <aop:config/> definition ensures that the transactional advice defined by the 'txAdvice' bean actually executes at the appropriate points in the program.

aop-config-xml

The above configuration is going to effect the creation of a transactional proxy around the object that is created from the 'fooService' bean definition.  [Foo Service might had @Transactional annotation]

The proxy will be configured with the transactional advice, so that when an appropriate method is invoked on the proxy, a transaction may be started, suspended, be marked as read-only, etc., depending on the transaction configuration associated with that method.

 

  • When you put @Transactional, Spring creates proxies for classes that declare @Transactional on the class itself or on members. The proxy is mostly invisible at runtime. It provides a way for Spring to inject behaviors before, after, or around method calls into the object being proxied

 

spring-declarative-tx-aop-proxyspring-declarative-tx-aop-proxy-trace

Also read:

http://stackoverflow.com/questions/25700599/how-does-transactional-works

http://stackoverflow.com/questions/1099025/spring-transactional-what-happens-in-background?rq=1

Proxy design pattern: http://codinko.com/2015/12/20/java-design-patterns/