Couldn't read committed data in TransactionalEventListener

19 Views Asked by At

I'm trying to read my previously committed data in @TransactionEvenListener annotated method which has default transaction phase but can't. Actually data is committing pretty fine, I can see it after transaction end, in DB or even if I do not use REQUIRES_NEW as propagation, I still can read in programmatically. The only thing I suspect is ChainedTransactionManager I used, which I do not know why but I can't see any other issues can cause this.

@Component
class MyTransactionalDomainEventHandler {

    private final MyRepository myRepository;

    @TransactionalEventListener
    @Transactional(transactionManager = "myChainedTransactionManager", propagation = Propagation.REQUIRES_NEW)
    public void onMyDomainEvent(MyDomainEvent event) {
        MyEntity myEntity = myRepository.findById(event.getEntityId()); //entity is inserted in transaction that cause to work this listener.
    }
}

But if I use REQUIRED as propagation then I can fetch my entity. TransactionalEventListener default has AFTER_COMMIT transaction phase, I expected it to commit before listener works. If it is committed then it shouldn't be issue to read it in other transaction, regardless of isolation level. Where am I doing wrong?

Edit: I debugged ChainedTransactionManager and saw it commit first transaction manager then TransactionalEventListener works without waiting others to commit. How to deal with this situation? I need to made it listen after all managers committed.

0

There are 0 best solutions below