为第三方对象配置javers ID



我正在尝试使用javers来存储我无法更改的第三方库中的对象。对象定义看起来像:

interface TheirObject extends WithId{    
  //Other properties here...
}
interface WithId{
  String getId();
}

具有该接口的各种实现。无论如何,ID字段都不会注释。

我尝试使用默认的javers配置并获得以下错误:

JaversException MANAGED_CLASS_MAPPING_ERROR: given javaClass 'interface TheirObject' is mapped to ValueObjectType, expected EntityType

所以我配置了javers如下:

javers = JaversBuilder.javers()
  .registerEntity(new EntityDefinition(TheirObject.class))
  .build();

给出例外:

JaversException ENTITY_WITHOUT_ID: Class 'TheirObject' mapped as Entity has no Id property. Use @Id annotation to mark unique and not-null Entity identifier

所以我尝试告诉它有关id字段的信息:

javers = JaversBuilder.javers()
  .withMappingStyle(MappingStyle.BEAN)
  .registerEntity(new EntityDefinition(TheirObject.class, "id"))
  .build();

给出例外:

JaversException PROPERTY_NOT_FOUND: Property 'id' not found in class 'TheirObject'. If the name is correct - check annotations. Properties with @DiffIgnore or @Transient are not visible for JaVers.

我尝试了几种不同的id变体(例如IdgetId(,但似乎没有任何作用,我没有发现该文档在计算如何继续进行的文档中很有用。

有人可以帮助我正确配置javers,以便我可以使用它来跟踪这些对象的更改?谢谢。

update :我已经更改了上面的界面以更好地反映问题,因为我过度简化了它,以至于我的示例实际上确实有效。

JaversBuilder.javers()
            .registerEntity(new EntityDefinition(TheirObject.class, "id"))        
            .build();

最新更新