Hello,
I am noob to AxonFramework and building a simple application to understand it. I am using Axon3, Kotlin 1.2.20.
I’ll paste the code below hoping it will make it clear.
// commands.kt
import org.hibernate.validator.constraints.Email
Hello,
I am noob to AxonFramework and building a simple application to understand it. I am using Axon3, Kotlin 1.2.20.
I’ll paste the code below hoping it will make it clear.
// commands.kt
import org.hibernate.validator.constraints.Email
Hi,
the problem is that you don’t specify any TransactionManager on your conmand bus. JPA requires a transaction to insert data in a database.
If you don’t specify a CommandBus explicitly, Axon will create one, and also automatically include the txManager.
You can simply autowire a ‘SpringTransactionManager’ in your commandBus() @Bean declaration and pass it inti the SimpleCommandBus constructor.
Cheers,
Allard
Here is the exception message as a whole:
o.a.c.c.C.[.[.[.[dispatcherServlet].log - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.axonframework.eventsourcing.eventstore.EventStoreException: An event for aggregate [fc593f69-b001-408a-80de-9d96bc5fa2c9] at sequence [0] could not be persisted] with root cause javax.persistence.TransactionRequiredException: No EntityManager with actual transaction available for current thread - cannot reliably process 'persist' call at org.springframework.orm.jpa.SharedEntityManagerCreator$SharedEntityManagerInvocationHandler.invoke(SharedEntityManagerCreator.java:282)
Thank you Allard. Here is how I did it
@Configuration
class AxonConfig {
@Bean
fun commandBus(transactionManager: TransactionManager): CommandBus {
val commandBus = AsynchronousCommandBus()
commandBus.registerHandlerInterceptor(TransactionManagingInterceptor(transactionManager))
return commandBus
}
}