I know this is probably a duplicate and, ironically, before I started reading here and there about it, I thought I knew what it was for (needless to say but I'll still say it, please correct me where I am wrong):
It relieves the programmer of having to use transaction.begin()
and commit()
.
If you have a method that calls two DAO methods which normally would each have a transaction.begin
and transaction.commit
encompassing the real operations and call them it would result in two transactions ( and there might be rollback issues if the previous DAO method was supposed to be rolled-back too).
But if you use @transactional
on your method then all those DAO calls will be wrapped in a single begin()
- commit()
cycle. Of course, in case you use @Transactional
the DAOs must not use the begin()
and commit()
methods I think.