Well, I possibly might be wrong in this question, but I need your valuable views/suggestions to stand on right path.
I want to know the good, better and best way to handle transaction management in Spring
+ Hibernate
, and Spring
+ JDBCTemplate
and pros and cons of each.
Some schemes/approaches that I know to do the same are:
1) Spring Transaction Management using AOP Annotations(@Aspect
, @PointCut
with Advice like @Before
, @After
, @Around
etc) .
Question - 1: I earlier done a Logging sample with Spring AOP, but i have no clue for doing the same for Transaction Management. Will the Transaction Start, Roll back and Commit will be done in that Aspect class with with Advice like @Before
, @After
, @Around
? Please share some code sample/snippet for this.
Question - 2: Does this approach required the Hibernate Transaction Manager Strongly, or can implemented without it?
2) Spring Transaction Manager with @Transactional
Annotation : Another transaction management scheme that involve Hibernate Transaction Manager for declarative transaction management with @Transactional
Annotation.
Question - 3: Using @Transactional
Annotation on a method guarantees all the transaction management in that method body but How will you manage the roll-back feature with this way in Multi-DAO operation on different entities in that particular method? Say,you are doing 3-4 different DAO operation(on different DAO Method with @Transactional) in that method and at 3rd DAO operation some exception occurs, How will you rollback.
Please share your views!
Regards,
Arun
PlatformTransactionManager
implementation which to use depends on which persistence mechanism you use or if you need to use JTA or not. Your transactional boundary should be the service layer not the individual dao methods (if you do the latter you will have multiple transactions instead of one). – M. Deinum@Before
and@After
or it is not the right choice to use them in this way? – Arun Kumar