Javers @diffIgnore на уровне класса / свойства не работает с наследованием - PullRequest
1 голос
/ 23 марта 2020

Мы создаем приложение, которое должно хранить различия, внесенные в существующие объекты. После этого мы будем хранить эти изменения в базе данных. Однако по какой-то причине опция @diffIgnore не работает с нашим классом User.class.

Каждый объект расширяет наш класс baseEntityCMS, который имеет свойство User. Это предназначено для хранения нашей обновленной пользовательской информации после сравнения JaVers По какой-то причине пользовательский объект все еще сравнивается даже после установки @diffIgnore на уровне свойств и на уровне класса.

Вот код:

BaseEntityCMS. java

public class BaseEntityCMS extends BaseEntity {

    private Boolean active;
    private LocalDateTime inactiveDateTime;
    private LocalDate creationDate;// in original application
    private LocalDate importDate;
    private LocalDate startDate;
    private LocalDate endDate;
    @Embedded
    @DiffIgnore
    private User modifierUser;

...
}

CodeList. java

public class CodeList extends BaseEntityCMS {

    private String companyCode;
    private Application sourceApplication;
    private String name;
    private String format;
    private int length;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "codeList")
    private List<Description> descriptionList;
    @ManyToMany(cascade = CascadeType.ALL, mappedBy = "codeListList")
    private List<Keyword> keywords;
    private String domainOwner;
    @OneToMany(cascade = CascadeType.REFRESH)
    private List<Attribute> attributeList;

...
}

Пользователь. java

@Embeddable
@AllArgsConstructor
@Builder
@DiffIgnore
public class User {

    private String userName;
}

TestCodeList. java

@Test
    public void compareCodeListTest() {

        Javers javers = JaversBuilder.javers().withListCompareAlgorithm(ListCompareAlgorithm.LEVENSHTEIN_DISTANCE)
                .registerValueObject(BaseEntity.class).registerValue(Code.class).registerValue(Attribute.class)
                .registerValue(AttributeValue.class).registerValue(MapCodeAttribute.class)
                .registerValueObject(User.class).build();

        CodeList codeListNew = createCodeListTest("ServiceTest");
        CodeList codeListNew2 = createCodeListTest("ServiceTest");

        Diff diff = javers.compare(codeListNew2, codeListNew);
        assertNull(diff.getChanges());
    }

Итак, в тестовом классе мы создаем 2 CodeLists (codeListNew и codeListNew2) стандартным методом. Внутри этого метода все создается одинаково, за исключением того, что мы каждый раз создаем нового пользователя. Поскольку все свойства codeList (attribute, attributeValue, ...) расширяют класс BaseEntityCMS, все они имеют свойство User.

Это вывод, который мы получаем:

changes on xxx.CodeList/ :
  - 'attributeList' collection changes :
    1. 'Attribute(name=Address, format=freeformat, length=10, numberOfDecimals=2, description=description attribute, optional=true)' changed to 'Attribute(name=Address, format=freeformat, length=10, numberOfDecimals=2, description=description attribute, optional=true)'
    0. 'Attribute(name=Number of employees, format=freeformat, length=10, numberOfDecimals=2, description=description attribute, optional=true)' changed to 'Attribute(name=Number of employees, format=freeformat, length=10, numberOfDecimals=2, description=description attribute, optional=true)'
  - 'mapCodeAttributeMap' map changes :
    'Code(super=BaseEntityCMS(super=BaseEntity(id=null), active=true, inactiveDateTime=null, creationDate=2020-03-23, importDate=2020-03-23, startDate=2020-03-23, endDate=2025-12-31, modifierUser=codems.agza.datalayer.model.User@57f83dc7), code=code1)' -> 'MapCodeAttribute(super=BaseEntity(id=null))' added
    'Code(super=BaseEntityCMS(super=BaseEntity(id=null), active=true, inactiveDateTime=null, creationDate=2020-03-23, importDate=2020-03-23, startDate=2020-03-23, endDate=2025-12-31, modifierUser=codems.agza.datalayer.model.User@75937998), code=code1)' -> 'MapCodeAttribute(super=BaseEntity(id=null))' removed

Мы на самом деле не ожидаем никакой разницы, поскольку все то же самое, кроме пользователя. Этот пользователь помечен @DiffIngore? Почему у нас все еще есть различия?

Забыл: мы используем

        <dependency>
            <groupId>org.javers</groupId>
            <artifactId>javers-core</artifactId>
            <version>5.8.11</version>
        </dependency>
...