Changes on event classes that were serialized and persisted

Hi everyone,

While working on a sample project, I got this exception after changing the package structure of my event classes. (Qualified name of event class is changed.):

…xstream.mapper.CannotResolveClassException : old_package_name.MyEventClass

So, serialized events that were saved to DB are tried to be deserialized. But their definitions were changed.

How can we migrate our data in these situations? I don’t have much experience on event sourcing.

Thanks in advance.
Bahadır Konu

Hi Bahadir,

generally, you use Upcasters to convert “old” serialized events to the new format. There is a small section about that in the reference manual: http://www.axonframework.org/docs/1.2/repositories-and-event-stores.html#d4e662

Alternatively, if you use XStream, you can add an alias from the old package name to the new one. To make sure the new events are stored under their own package name, you have to add the alias twice, like so:\

serializer.addPackageAlias(“old.package.name”, “new.package.name”); // makes sure old package is read in as new.package
serializer.addPackageAlias(“new.package.name”, “new.package.name”); // makes sure that new.package is also written as new.package

This removes the need for upcasters and performs a lot better too.

Cheers,

Allard

2011/11/29 Bahadır Konu <bahadir.konu.axon@gmail.com>