2017-07-03 47 views
0
audditing時如何忽略父類的字段

我從anothers延伸的實體,這樣的:與Javers

public class House extends Building{ 
public Integer idHouse 
} 

public class Building extends Structure{ 
} 

public class Structure { 
public Integer field1; 
} 

我需要審計在衆議院對象的變化,但我不希望包括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!

回答

0

你可以爲這個問題展示一個失敗的測試用例嗎?

我寫的測試(常規),一切看起來很好 (你的實體只有一個屬性 - 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 
}