如何在使用Javers进行审计时忽略父类中的字段

时间:2017-07-03 09:38:55

标签: auditing 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"。我也试图映射结构类,但我不能,因为它没有id。

关于如何忽略field1的任何想法? THX!

1 个答案:

答案 0 :(得分:0)

您能否针对该问题展示失败的测试用例?

我写了测试(groovy),一切看起来都很好 (您的实体只有一个属性--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
}