Axon Unit of work not working.

Hi, I am using axon version3.0-M5. while calling repository.load, it showing “no unity of work found”. The following is my configuration. Could you please help me.



public class BookCqrsApplication {

public static void main(String[] args) {, args);



public EventStorageEngine eventStorageEngine() {

return new InMemoryEventStorageEngine();



public Repository jpaRepo(EventBus eventBus) {

return new GenericJpaRepository<>(entityManagerProvider(), Book.class, eventBus);



public EntityManagerProvider entityManagerProvider() {

return new ContainerManagedEntityManagerProvider();



private EntityManagerFactory entityManagerFactory;


private SpringTransactionManager springTransactionManager;


public SpringTransactionManager springTransactionManager() throws Exception {

return new SpringTransactionManager(transactionManager());



public PlatformTransactionManager transactionManager() throws PropertyVetoException {

return new JpaTransactionManager(entityManagerFactory);



public TransactionManagerFactoryBean transactionManagerFactoryBean() throws PropertyVetoException {

TransactionManagerFactoryBean factoryBean = new TransactionManagerFactoryBean();


return factoryBean;




I’m unsure what happens here:

UnitOfWork uow = DefaultUnitOfWork.startAndGet(transactionManager);

That method only takes Messages so I’m not sure how the code compiles (or it may be that something went wrong while copy-pasting the code).

Note that the command bus creates a unit of work for you (rarely if ever do you need to create a unit of work yourself). So if you dispatch a command to create a book it shouldn’t complain about a missing unit of work.



Very Very thanks for your reply. :slight_smile:

I am very new to Axon and CQRS. My intention was to create a BookStore in Mysql DB using JPA+Spring and Axon.
I am getting the following exception while executing the bellow code. (I removed the UnitofWork code for now).
Could you please check it and reply, what the error is.

(I am attaching my complete source code with this mail)

Controller (8.74 KB)


the problem is in the jpaRepo.load() call (I suppose this is an Axon repository?). You’re not supposed to load the book from the repository yourself. Instead, send a command on the Command Bus and let Axon manage loading the aggregate instance for you. You retrieving the book, but only using the ID from the retrieved object (which is the same as the input, I presume) to create the command.

Check out the Getting Started webinar to see how this works:

Hope this helps.