I have a transaction issue on COR pattern:
AbstractChainHandler
| |
| |
FirstChainHandler SecondChainHandler
-create A -create B
-delete A -delete B
FirstChainHandler and SecondChainHandler both extend AbstractChainHandler and they do some persistence tasks. Is it possible to handle transaction so if SecondChainHandler fails to save B on db also FirstChainHandler does the rollback of A persistence?
I am trying with spring @Transactional but it is not working and I am not sure if COR pattern matches my goal. I tryied to change propagation and isolation configurations but it didn't work.
As a first option I would try to combine creation of A and B into single transaction. Maybe it's possible to handle transactions at the base class level? Another option is to combine the classes
FirstChainHandler
andSecondChainHandler
into one. This would make it easy to handle the transactional part.The second option adds complexity so I wouldn't go there if not absolutely necessary. With Saga and/or Compensating Transaction patterns you can achieve eventual consistency.