Can't persist event into event store due to lack of EntityManager

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**

I should have searched the forum. Sorry for the inconvenience. Need to @Transactional. I guess that is how Axon’s code itself is doing, correct? :slight_smile:

Hi Chun Fu,

@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.

Cheers,
Steven