1

我有以下类层次结构:

class Incident {// Id => Entity
  @Id
  String id
  List<Participant> participants
  List<RealEstateProperty> realEstateProperties
}

在哪里

class Participant {// No id => by javers terms - ValueObject
   EnclosedContact contact
}

class EnclosedContact {// No id => by javers terms - ValueObject
  String name
}

class RealEstateProperty {// No id => by javers terms - ValueObject
   List<CadastralSection> cadastralSections
}

class CadastralSection {// No id => by javers terms - ValueObject
  String sectionId
}

我已经编写了以下测试(在常规中):

def "Querying Javers Repository for participants changes works correctly"() {
    given:
    (1..3).each {
        javers.commit("author", new Incident(
            id: it,
            participants: [
                new Participant(contact: new EnclosedContact(id: 20 + it))
            ]
        ))
    }

    when:
    def snapshots = javers.findSnapshots(QueryBuilder.byValueObjectId(1, Incident.class, "contact").build())

    then:
    assert snapshots.size() == 1
}

这个测试的结果是:

JaversException: PROPERTY_NOT_FOUND property 'contact' not found in class 'Incident'

试图以这种方式进行更改

def snapshots = javers.findSnapshots(QueryBuilder.byValueObjectId(1, Incident.class, "participants/0/contact").build())

返回空列表。

Javers 是否支持在嵌套的 ValueObjects 上选择更改?

4

3 回答 3

2

在 JaVers 1.6.2 中有对嵌套 ValueObjects 查询的基本支持(尚未记录)。您的查询应该适用于此 JaVers 版本保留的数据。例如:

def "should query for changes on nested ValueObjects stored in a list"(){
    given:
    def user = new DummyUserDetails(
        id:1,
        addressList: [new DummyAddress(networkAddress: new DummyNetworkAddress(address: "a"))])

    javers.commit("author", user)
    user.addressList[0].networkAddress.address = "b"
    javers.commit("author", user)

    when:
    def changes = javers.findChanges(QueryBuilder.byValueObjectId(1, DummyUserDetails,
            "addressList/0/networkAddress").build())

    then:
    changes.size() == 1
    changes[0].left == "a"
    changes[0].right == "b"
}
于 2016-04-14T06:11:00.033 回答
1

我创建了一个通用的嵌套对象比较器,希望它有所帮助。

https://gist.github.com/hank-cp/3db40faed1dd9f02ababd86c2c9eaf8d

像这样注册它:

NestedObjectComparator productRootComparator =
        new NestedObjectComparator<POProductRoot>() {};
sharedJavers = JaversBuilder.javers()
        .registerValue(POProductRoot.class)
        .registerCustomComparator(productRootComparator, POProductRoot.class).build();
productRootComparator.setJsonConverter(sharedJavers.getJsonConverter());

然后您将获得MapChange格式的更改结果。

于 2016-08-11T02:44:12.583 回答
0

从 JaVers 2.1 开始,有一个用于此类查询的新过滤器 - child-value-objects-filter

于 2016-08-04T21:15:04.580 回答