0

我有一个从其他实体延伸出来的实体,例如:

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的任何想法?谢谢!

4

1 回答 1

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
}
于 2017-07-03T20:21:58.090 回答