Is it possible to get previous version aggregate in Axon 2?

I am a newbie with Axon.

Is it possible to get previous version aggregate in Axon 2?
for example:
an entitiy’s current version is 3, How do I get the 2nd version of this entity by eventsourcingrepository?

Hi Zeshu,

with the default Axon Repository, it is only possible to load the latest (current) version of an aggregate. However, if you really need to load another version, you would have to load the stream from the event store and wrap it, so that is return false on hasNext() when the next has a too-high sequence number. Then create an aggregate instance and feed it the wrapped event stream.

I do wonder why you would need this. You might be needing this to perform a query, in that case: stop, drop & roll :wink: Use a query model instead.



Thanks for help.
One of my requirements is to be able to view all historical changes of the entity.
If it can not do it, I can only find other ways.

2017年2月24日金曜日 20時36分01秒 UTC+8 Allard Buijze:


that’s exactly what a view model would be used for. You will just need to create a view model that creates a new entry for every state available (or have one created on-demand).

The command model is only for accepting commands, not for providing information. At least, not if you apply CQRS.



It's a thin line though. If you need an audit log for an AR I would have no issue with bringing the event stream on screen, provided the events are somewhat understandable for the user, not always the case for complex ARs.