When creating an Axon JPA state-based aggregate is there a way to mark certain fields as being the @CreatedDate and @LastModifiedDate (as is possible with spring data jpa)?
In other words does Axon have the functionality where if any state of the aggregate is changed then axon automatically updates the @LastModifiedDate
without us having to repeat it in every @CommandHandler
?
Try using @CommandHandlerInterceptor inside your aggregate to intercept all commands and set lastModifiedDate field.
@CommandHandlerInterceptor
public Object intercept(Object myCommand, InterceptorChain interceptorChain) throws Exception {
this.lastModifiedDate = Instant.now();
return interceptorChain.proceed();
}