I have some doubts regarding the Transactions Propagation & Isolation levels. Consider the code snippet below:
I have below doubts:
1. Where we need to put the Propagation levels: On method m1 or m2? I hope it needs to be on m2?
2. Can we place propagation level on both the methods as well? I hope it can't be on m1?
3. Where we can put the isolation levels? I think it needs to be placed on just one method and it will be applicable to that method only, please correct me if I am wrong.
TX isolation and propagation are DB concepts, not so much Java concepts. Start by analyzing the concurrency of your multi-user application, and balance that against the need for speed. It may well turn out that you do not need to worry at all. In my 20+ years of professional work with DB-based Java apps I haven't had to consider this issue much. Why do you think you need to?
I am going through the spring transactions and there is so much emphasis on these concepts there. I am just thinking if it can be handled at DB side then why there is a provision of these on java APIs.
And I can understand that isolation can be handled at DB side but just unable to grasp that propagation can be handled at DB side since it is a related to one method rivalling another method and transaction boundaries withinmethods I may be wrong because I am not an expert.
Imagine two users connecting to your system and executing transactions at about the same time. They are both going to be accessing the database at about the same time, possibly overlapping. That's why you need transactions.