I am trying to find a better way to handle transactions at the object level (and not at the database level). A brief example: 4 objects A, B, C, and D. A starts a transaction and calls methods in B and C. At the same time, transaction C also calls D. Called methods should not always participate in this transaction, but they can be called themselves by oneself. Are there any templates for object level transaction management?
I really did not find anything, so I came to the following: use TransactionContext where you can register TransactionListeners. If a transaction is launched using TransactionContext, it will enter the launched transaction into each registered listener, which, in turn, will use the launched transaction or, accordingly, start it on its own, if necessary. That way, I can freely decide if I want the object to participate in my transaction or not.
The problem occurs when there is a chain of object calls, as described above. When starting a transaction, I just know that B and C must be involved in the transaction, so I add them to the TransactionContext. But what about D? I really don't want to pass the TransactionContext to B and C.
I would appreciate some input to my approach, as well as some pointers to tested samples (even better).
source
share