I am working on replacing my PoC InMemoryEventStore and query models stored in HashMap to JPA versions, so my program can survive restart
In the debugger it looks like Axon finds the Spring TransactionManager and gets the UoW bound to a transaction.
I get this exception when dispatching the command:
java.lang.IllegalStateException: Could not clear this UnitOfWork. It is not the active one.
at org.axonframework.messaging.unitofwork.CurrentUnitOfWork.clear(CurrentUnitOfWork.java:139)
at org.axonframework.messaging.unitofwork.AbstractUnitOfWork.commit(AbstractUnitOfWork.java:75)
at org.axonframework.messaging.unitofwork.DefaultUnitOfWork.executeWithResult(DefaultUnitOfWork.java:80)
at org.axonframework.commandhandling.SimpleCommandBus.handle(SimpleCommandBus.java:156)
at org.axonframework.commandhandling.SimpleCommandBus.doDispatch(SimpleCommandBus.java:127)
at org.axonframework.commandhandling.SimpleCommandBus.dispatch(SimpleCommandBus.java:91)
at org.axonframework.commandhandling.gateway.AbstractCommandGateway.send(AbstractCommandGateway.java:79)
at org.axonframework.commandhandling.gateway.DefaultCommandGateway.send(DefaultCommandGateway.java:95)
at org.axonframework.commandhandling.gateway.DefaultCommandGateway.sendAndWait(DefaultCommandGateway.java:113)
at dk.bec.etl.simulator.rest.DemoRestService.anmeld(DemoRestService.java:108)
are you doing anything “manually” with Unit of Work anywhere? Like committing it, or rolling one back?
This error means that a Unit of Work is being committed, but it is not currently the active one. It might be because there is Unit of Work nesting and the inner unit of work hasn’t been committed or rolled back, yet. Generally, you should not have to bother with Unit of Work, and you should also not see this message, unless you start managing your own unit of work.
I investigated a bit more and the error I got when I get the Unit of Work exception is actually a stackoverflow.
You can get that by making two @Entity classes with a simple parent / child relationship with JPA annotations, and then use the @Data annotation from Lombok, instead of getters and setters.
Apparently that combination produces an infinite loop because hibernate will call the generated lombok tostring/hashcode methods, that call each other…
But I also wonder why the error got swallowed by axon. It was hard enough to find as it was