I am a newbie to spring hibernate.
And I find 2 ways to handle transactions in Spring declaratively - ProxyFactoryBean using TransactionInterceptor or the @Transactional annotation.
How do we decide which one to prefer?
Is there any other way available for declarative transaction management too?
0
votes
1 Answers
0
votes
Advantages of annotaions way:
- Annotations are directly visible in the code.
Advantages of xml way:
- You can reuse the same conf between multiple beans
- You can share some class between two applications and apply different transaction rules
I prefer annotations where it is possible. It saves a lot of time when you read the code (you do not need open one more file and check it periodically).
Other way for declarative transactions: use <aop:config> with <tx:advice>. See corresponding entry in official documentation. It is a variation of xml way that is more easy to do then ProxyFactoryBean (you do not need to wrap beans / declare transaction interceptor manually).
Hope this helps.