I want to know what actually happens when you annotate a method with `@Transactional`?
Of course, I know that Spring will wrap that method in a Transaction.

But, I have the following doubts:

1. I heard that Spring creates a **proxy class**? Can someone explain this in more **depth**. **What actually resides in that proxy class? What happens to the actual class? And how can I see Spring's created proxied class**
2. I also read in Spring docs that:

> 
> *Note: Since this mechanism is based on proxies, **only 'external' method calls coming in through the proxy will be intercepted**. This means that 'self-invocation', i.e. a method within the target object calling some other method of the target object, won't lead to an actual transaction at runtime even if the invoked method is marked with `@Transactional`!*
> 
> 
> 

Source: <http://static.springsource.org/spring/docs/2.0.x/reference/transaction.html>

**Why only external method calls will be under Transaction and not the self-invocation methods?**
['https://Stackoverflow.com/questions/1099025', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/133830/']
When Spring loads your bean definitions, and has been configured to look for `@Transactional` annotations, it will create these **proxy objects** around your actual **bean**. These proxy objects are instances of classes that are auto-generated at runtime. The default behaviour of these proxy objects when a method is invoked is just to invoke the same method on the "target" bean (i.e. your bean). 

However, the proxies can also be supplied with interceptors, and when present these interceptors will be invoked by the proxy before it invokes your target bean's method. For target beans annotated with `@Transactional`, Spring will create a `TransactionInterceptor`, and pass it to the generated proxy object. So when you call the method from client code, you're calling the method on the proxy object, which first invokes the `TransactionInterceptor` (which begins a transaction), which in turn invokes the method on your target bean. When the invocation finishes, the `TransactionInterceptor` commits/rolls back the transaction. It's transparent to the client code.

As for the "external method" thing, if your bean invokes one of its own methods, then it will not be doing so via the proxy. Remember, Spring wraps your bean in the proxy, your bean has no knowledge of it. Only calls from "outside" your bean go through the proxy.

Does that help?
**The simplest answer is:** 

On whichever method you declare `@Transactional` the boundary of transaction starts and boundary ends when method completes. 

If you are using JPA call then **all commits are with in this transaction boundary**. 

Lets say you are saving entity1, entity2 and entity3. Now while saving entity3 an **exception occur**, then as enitiy1 and entity2 comes in same transaction so entity1 and entity2 will be **rollback** with entity3.

**Transaction :**

> 
> 1. entity1.save
> 2. entity2.save
> 3. entity3.save
> 
> 
> 

Any exception will result in rollback of all JPA transactions with DB.Internally JPA transaction are used by Spring.