No 'given' events were configured for this aggregate

Hi,

For the initial creation of the aggregate, I don’t have any previous events, just the starting command such as :

fixture
        .givenNoPriorActivity()
        .when(new RegisterHotel(....))
        .expectVoidReturnType()
        .expectEvents(new HotelRegistered(...))
;

However, when running this test I keep getting the following error, any ideas what i’m doing wrong?

org.axonframework.repository.AggregateNotFoundException: No ‘given’ events were configured for this aggregate, nor have any events been stored.

1

Hi,

did you put your @CommandHandler annotation for the RegisterHotel command on a constructor?

Cheers,

Allard

No I didnt, I’ve handled the command in my Aggregate such as…

final class Hotel extends AbstractAnnotatedAggregateRoot {

    @AggregateIdentifier
    private String id;

    public Hotel() {
    }

    @CommandHandler
    public void on(RegisterHotel cmd) {
        apply(new HotelRegistered(...));
    }

Since it’s the command that creates a new hotel instance, it should be a constructor instead of an instance method. Replace “void on” by “Hotel” and you’re all set.

Brilliant, that works, thanks!