Как игнорировать поля в родительском классе при аудите с помощью Javers

У меня есть сущность, которая простирается от других, например:

public class House extends Building{
 public Integer idHouse
}

public class Building extends Structure{
}

public class Structure {
 public Integer field1;
}

Мне нужно проверить изменения в объектах House, но я не хочу включать поле Structure.field1. Я пробовал это:

String skippedFields = ["field1"];
        EntityDefinition houseEntity =
                EntityDefinitionBuilder.entityDefinition(House.class)
                .withIdPropertyName("idHouse")
                .withIgnoredProperties(Arrays.asList(skippedFields))
                .build();

Javers javers = JaversBuilder.javers()
 .registerEntity(expedienteEntity)
    .registerJaversRepository(sqlRepository).build();

Но, похоже, игнорируется «IgnoeredPropertied». Я также пытался сопоставить класс структуры, но не могу, потому что у него нет идентификатора.

Любые идеи о том, как я могу игнорировать field1? Спасибо!


person Nuria    schedule 03.07.2017    source источник


Ответы (1)


Можете ли вы показать неудачный тестовый пример для этой проблемы?

Я написал тест (groovy), и все выглядит нормально (у вашего Entity есть только одно свойство — idHouse):

class StackCase extends Specification {

    class Structure {
        public Integer field1
    }

    class Building extends Structure{
    }

    class House extends Building{
        Integer idHouse
    }

    def "should use IgnoredProperties "(){
      given:
      def houseEntity =
              EntityDefinitionBuilder.entityDefinition(House)
                      .withIdPropertyName("idHouse")
                      .withIgnoredProperties(["field1"])
                      .build()

      def javers = JaversBuilder.javers()
              .registerEntity(houseEntity).build()

      def entityType = javers.getTypeMapping(House)
      println entityType.prettyPrint()

      expect:
      entityType.properties.size() == 1
    }
}

выход:

22:16:51.700 [main] INFO  org.javers.core.JaversBuilder - JaVers instance started in 723 ms
EntityType{
  baseType: class org.javers.core.StackCase$House
  typeName: org.javers.core.StackCase$House
  managedProperties:
    Field Integer idHouse; //declared in House
  idProperty: idHouse
}
person Bartek Walacik    schedule 03.07.2017