1

Let's say I have a rest call which creates some object "A" in the database. Method is marked with @Transactional annotation. And just after creation I need to launch another asynchronous process in another thread or through some messaging system or in some other async way. That new process depends on the object "A" and needs to see it.

How can I make sure that transaction is commited before new process starts execution?

For example in Spring there is

TransactionSynchronizationManager.registerSynchronization(new TransactionSynchronization(){
           void afterCommit(){
                //do what you want to do after commit
           }
})

Does Quarkus has something similar?

Dmitry Shohov
  • 322
  • 2
  • 9

1 Answers1

1

You can inject TransactionManager

@Inject
TransactionManager transactionManager;

and do

Transaction transaction = transactionManager.getTransaction();
transaction.registerSynchronization(new Synchronization() {
                @Override
                public void beforeCompletion() {
                    //nothing here
                }

                @Override
                public void afterCompletion(int status) {
                    //do some code after completion
                }
            });
Dmitry Shohov
  • 322
  • 2
  • 9