Can someone help me understand how the EntityManager is attached to the current thread? I spawn a new thread myself and tried to publish an event using
eventBus.publish(). And I am getting the following exception. Thanks in advance for the help.
**Caused by: javax.persistence.TransactionRequiredException: No EntityManager with actual transaction available for current thread - cannot reliably process 'persist' call**
@Transactional definitely does the trick, yes.
The framework internally however does this per message through means of the UnitOfWork (the UnitOfWork#attachTransaction(TransactionManager) to be exact).
As every message within Axon is dealt with as a UnitOfWork, this approach effectively covers the transactional boundaries.