I have the problem that the field in the abstract class “uitworpAggregateId” will not be found by the fixture method registerIgnoredField().
But the field “gebeurtenisId” is found.
@EqualsAndHashCode
@Getter
@SuperBuilder(toBuilder = true)
@ToString
public abstract class AbstractUitworpAggregateEvent {
public UUID uitworpAggregateId;
public UUID myAggregateId;
}
@EqualsAndHashCode(callSuper = true)
@Getter
@Jacksonized
@SuperBuilder(toBuilder = true)
@ToString(callSuper = true)
public class UitworpAggregateAanmakenEvent extends AbstractUitworpAggregateEvent {
private final UUID gebeurtenisId;
}
spring boot version 3.4.1
axon version 4.10.4
java 21
It seams that in the class org.axonframework.test.matchers.IgnoreField
some methods does not loop correctly trough all the classes.
public IgnoreField(Class<?> clazz, String fieldName) {
try {
ignoredField = clazz.getDeclaredField(fieldName);
} catch (NoSuchFieldException e) {
throw new FixtureExecutionException("The given field does not exist", e);
}
}
It seems this is a feature, not a bug. As stated in the documentation for the registerIgnoredField method:
“Indicates that a field with the given {@code fieldName}, which is declared in the given {@code declaringClass}, is ignored when performing deep equality checks.”
As you can see, the gebeurtenisId field is not declared in the class itself, but in its superclass.
I propose to use one of those three solutions:
Use the method and pass the abstract event type like this: fixture.registerIgnoredField(AbstractUitworpAggregateEvent.class, "uitworpAggregateId");. If you have a field in an abstract class and want to ignore it for every event that extends this type,
Leverage the framework’s flexibility and use the fixture.registerFieldFilter method to implement a custom FieldFilter, you may implement it as you suggested in your message.
I assume UitworpAggregateAanmakenEvent it’s the creation event for the aggregate. Where do you generate the UUID? In the aggregate? If it’s the case, instead of ignoring the field, I recommend passing the UUID (generate it where the command is invoked) as an argument to the command that creates the aggregate. This approach eliminates the need to ignore the field and ensures the UUID is set correctly and not mixed up with other UUIDs.
Thanks for the quick response.
I fixed the problem with Allard his answer.
As always it seems there where 2 problems.
Fixed the ignore field by using point 1 fixture.registerIgnoredField(AbstractUitworpAggregateEvent.class, "uitworpAggregateId");
Second issue not described above was moving place of how the aggregate creating took place.