Should I be placing @Transactional before @TransactionalEventListener annotations ?
The following code only works when I place @Transactional before the @TransactionalEventListener :
@Transactional
@TransactionalEventListener
public void onUserMessageChangedAfterCommit(EntityChangedEvent<UserMessage> event) {
try {
if (event.getType() == EntityChangedEvent.Type.CREATED) {
UserMessage userMessage = dataManager.load(event.getEntityId())
.joinTransaction(false)
.fetchPlan("userMessage-fetch-plan")
.one();
UserMessageEvent userMessageEvent = new UserMessageEvent(this,
userMessage.getSubject(),
userMessage.getMessage(),
true,
userMessage.getRecipients(),
userMessage.getSender(),
false,
userMessage.getSendToAll());
globalUiEventPublisher.publishEvent(userMessageEvent);
}
} catch (Exception e) {
log.error("Error handling User Message changes after commit", e);
}
}
If I do not include @Transactional then I receive the error:
TransactionRequiredException:
Exception Description: No transaction is currently active
Why is this so ?