Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

It appears that both the AOP and @Transactional configuration can be used , and together; the same proxy object will be used.

What all these schemes are doing is specifying allowing us to configure all aspects of our database transactions, for example to specify where the transactional boundaries should be in our application.

So, given three methods of configuration, what should we use?

Of the three methods for configuring transactions, the TransactionProxyFactoryBean is the oldest and should probably no longer be used. The Spring docs go into detail about AOP and @Transactional, only mentioning TransactionProxyFactoryBean in a sidebar. I wouldn't be surprised if TransactionProxyFactoryBean were deprecated and dropped in future versions of Spring.

Moving exclusively to @Transactional means modifying a lot of existing Java code and converting existing project configurations.

AOP seems to be the cleanest method - transactions can be configured without modifying Java code.

Although AOP and @Transactional can be mixed, there could be issues with unpredictable behavior where the two configurations collide. For this reason, it is probably not a good practice to mix.

This leaves us with - using AOP.

For the most part, the propagation behavior is specified as "REQUIRED", which means that if there is a transaction in progress, the code will participate in that transaction, but it there is no transaction in progress, a new transaction will be created.

...