2
votes

Using axon framework I've got error:

Aggregate identifier must be non-null after applying an event. Make sure the aggregate identifier is initialized at the latest when handling the creation event. I use this StorageEngine:

@Bean
public JdbcEventStorageEngine jdbcEventStorageEngine() throws Exception{
    return new JdbcEventStorageEngine(dataSource::getConnection, NoTransactionManager.INSTANCE);
}

Code fails when the message for aggregateId is recieved second time like in this handler:

@CommandHandler
public void handle(CreateProductCommand command) throws Exception {
    Aggregate<Product> productAggregate = null;
    try {
      productAggregate = repository.load(command.getId());
    } catch (AggregateNotFoundException exception) {
      logger.info("Aggregate with " + command.getId() + " is not found. Creating new one...");
      productAggregate = repository.newInstance(() -> new Product(command.getId()));
    }
    productAggregate.execute(product -> product.createProduct(command.getId()));
}

But if I use this it works fine:

@Bean
public EventStorageEngine eventStorageEngine() {
  return new InMemoryEventStorageEngine();
}

How I should configure eventStorageEngine for postgres/mysql database?

1

1 Answers

3
votes

Removing spring devtools worked out nicely.