Snaphoot saved without payload

Hi, Axon forum!

I have experimented with Snaphooting and the default config for it.
My config is:

	@Bean
	public Repository<ProductAggregate> productAggregateRepository(EventStore eventStore,
			SnapshotTriggerDefinition subscriptionSnapshotDefinition)
	{
		return EventSourcingRepository.builder(ProductAggregate.class)
				.snapshotTriggerDefinition(subscriptionSnapshotDefinition)
				.eventStore(eventStore).build();
	}

	@Bean("productSnapshotDefinition")
	public SnapshotTriggerDefinition productSnapshotDefinition(Snapshotter snapshotter)
	{
		return new EventCountSnapshotTriggerDefinition(snapshotter, 1);
	}
@Aggregate
		(snapshotTriggerDefinition = "productSnapshotDefinition")
public class ProductAggregate

Shaphot is done.
But after all command/event for update more than 2 times the exception is throwing:

org.axonframework.eventsourcing.IncompatibleAggregateException: 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.

After that I noticed that that payload in table snapshot_event_entry is empty:
image
and probably the issue is related.
domain_event_entry is ok and payload is stored.

My question should I add something else for populating payload as well?

The second question what is the best practice to get the latest snapshot for Aggregate?
eventStore.readEvents(productId).asStream() contains only events.

I didn’t find in the documentation how can I retrieve snapshot by Aggregate Id.

Thanks in advance!

For the first part, you likely need some custom configuration for the ObjectMapper used by Jackson, this could look something like:

    @Bean
    ObjectMapper objectMapper() {
        PolymorphicTypeValidator ptv = BasicPolymorphicTypeValidator
                .builder()
                .allowIfSubType(List.class)
                .allowIfSubType(Map.class)
                .build();
        JsonMapper mapper = JsonMapper
                .builder()
                .activateDefaultTyping(ptv)
                .build();
        mapper.registerModule(new JavaTimeModule());
        mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS, false);
        mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
        mapper.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
        return mapper;
    }

Where for this particular issue, the change of the visibility likely fixes the problem.

Thanks @Gerard! I will try.

What about the second question, how to retrieve a snapshot?

There is method org.axonframework.eventsourcing.AggregateSnapshotter#createSnapshot
But I can’t find something similar to retrieve it.

Moreover, it is stored separately in snapshot_event_entry.

Will appreciate your answer

The Snapshotter will store the snapshot in the EventStore. The bit of code that tries to find a snapshot, can be found here. With the readSnapshot implement here.