Snapshot aggregate is empty

Hello all,

I’m trying to use the snapshot feature with Axon 3.0.6 or 3.0.7. Basically, I set up a repository this way:

`

new CachingEventSourcingRepository<>(new GenericAggregateFactory<>(MyAggregate.class),
eventStore(), new PessimisticLockFactory(), hazelcastCache(), new EventCountSnapshotTriggerDefinition(new AggregateSnapshotter(eventStore(), new GenericAggregateFactory<>(MyAggregate.class)), 3));

`

Every three events, the storeSnapshot() method of my own EventStorageEngine is well triggered. Yet the DomainEventMessage passed is unfortunately empty.

If I put a breakpoint line here I can see the eventStream is correctly filled with three events but after this step, the aggregateRoot is not modified. It remains empty.
Nonetheless in the logs I saw it triggered my @EventSourcingHandler methods. It’s like an aggregate instance was modified but the AggregateSnapshotter was not able to retrieve this very instance.

My aggregate is defined like this:

`

@Aggregate
@AggregateRoot
public class MyAggregate extends DomainAggregate { //DomainAggregate is my own abstract class
@AggregateIdentifier
@TargetAggregateIdentifier
private String aggregateId;

//Some stuff
}

`

Am I missing something? Like a specific annotation somewhere?

Thanks

Hi,

is your aggregate properly event source? Meaning, does it set all the fields using @EventSourcingHandler annotated methods?

Also, I notice you’ve got both @AggregateRoot and @Aggregate annotations. The first one is not necessary (it doesn’t harm either). Then, the @TargetAggregateIdentifier on the aggregateId field doesn’t make sense. This annotation should be put on commands to identify the field that expresses the command’s target.

Cheers,

Allard

Hi,

Okay actually I’ve added both annotations (@AggregateRoot and @TargetAggregateIdentifier) just for this test but fine I cam back to my original point.

Is your aggregate properly event source?

Yes it is. I mean I am able to reconstruct an aggregate based on the event stored. That’s strange.

Are you using Spring?

I notice that you didn’t configure a TransactionManager on the AggregateSnapshotter. Where are you storing snapshots? If it’s using JPA, you’ll need a transaction to be able to persist the snapshot. You might also want to autowire the ParamterResolverFactory from your Spring context (assuming Spring).

Cheers,

Allard

Yes I am but am I really able to use the SpringBeanParameterResolverFactory here? I feel like using a simple DefaultParameterResolverFactory should make the job. Otherwise it seems I have to beanerize my event classes by using a @Service for instance.

But still is that really related to how I am storing the snapshots? I have using Event Store for that and a custom EventStorageEngine. The storeSnapshot() is well invoked, the only thing is that the snapshot parameter is empty. I feel like something is missing before.

My bad Allard, this was a mistake somewhere in my code.

Thanks for the help anyway, the implem will be cleaner with your piece of advice.