Closed abuijze closed 7 years ago
Why can't we obtain the generic Class<?>
parameter in the constructor using refelction?. Thus no API changes are required.
In Axon 2, the API's are changing anyway. So it's not really a problem.
It's possible to find out what aggregate should be stored using reflection on the generi parameters, but that's not full-proof.
From an email conversation: The symptoms were the following :
When looking to Hibernate logs, I saw that the DomainEventEntry corresponding to the creation of Bar actually had the aggregateType "Foo" when being inserted in the db.
Ok, so one big headache later, I came to realize that I hadn't declared the event sourcing repository for Bar in my Spring app context. So, instead of telling right to my face that I'm stupid, it looks like Axon just tried to use another repository to store the event... which worked. But, deserializing is another story :)
Expected behavior Repositories should throw an exception when the type of aggregate is not assignable to the type they are configured to store.
Implementation details The AbstractRepository should get a Class in its constructor that corresponds with the generic parameter of the Repository. This class can be used to verify the type of incoming aggregates.
Requires API change.