3

Call a Spring Bean method with different transaction attributes?

 2 years ago
source link: https://www.codesd.com/item/call-a-spring-bean-method-with-different-transaction-attributes.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Call a Spring Bean method with different transaction attributes?

advertisements

What happens if a transactional method with certain transaction attributes call a method at the same bean with different transaction attributes?


With standart transactional configutration in Spring nothin will happen. From documentation (look in reference documentation for full explanation of declarative transaction management):

In proxy mode (which is the default), only external method calls coming in through the proxy are intercepted. This means that self-invocation, in effect, a method within the target object calling another method of the target object, will not lead to an actual transaction at runtime even if the invoked method is marked with @Transactional.

If you need to change transactional behaviour (propagation, read only status and etc.) using a method call at the same bean you can change transaction mode to AspectJ and using compile time wieving (look here how to do this). But I have never do this in real practice, just for test. Usually it is enough default transactional settings.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK