1

我有一个应用程序实体和一个用户实体。应用程序与用户之间存在一对多关系,即一个应用程序可以有多个用户。
我更新用户并更改分配给他的应用程序。到目前为止,我有以下内容:

Diff diff = javers.compare(oldUser, newUser);
List<ReferenceChange> referenceChanges = diff.getChangesByType(ReferenceChange.class);
for (ReferenceChange referenceChange : referenceChanges) {
            Object oldRef = referenceChange.getLeftObject().get();
            Object newRef = referenceChange.getRightObject().get();             
            Diff refDiff = javers.compare(oldRef,newRef);               
        }

请在调试时找到以下结果:
referenceChanges List:
ReferenceChange{globalId:'com.ds.appmanager.services.domain.User/3', property:'application', oldRef:'com.ds.appmanager.services.domain。 Application/7', newRef:'com.ds.appmanager.services.domain.Application/3'}
oldRef
应用程序 [applicationId=7, applicationName=KYC, applicationDesc=DEV_TEST, applicationLaunch=2016-12-31 00:00:00.0 , live=false]
newRef
Application [applicationId=3, applicationName=KYC, applicationDesc=hellp, applicationLaunch=Sat Mar 12 00:00:00 IST 2016, live=true]

当我将两个对象都传递给 javers.compare(oldRef,newRef) 时,它再次给了我与referenceChanges相同的结果。我认为它应该给我每个属性的值更改,例如 applicationDesc、oldVal = DEV_TEST、newVal = hellp。

我在这里错过了什么吗?我要做的就是获取在 User 对象中引用的 Application 对象的属性值更改。

PS:如果我更改Object oldRef = referenceChange.getLeftObject().get();Object oldRef = referenceChange.getLeftObject();,我会得到JaversException: CLASS_EXTRACTION_ERROR JaVers bootstrap error - Don't know how to extract Class from type 'T'.

更新
刚刚注意到我在进行
Diff refDiff = javers.compare(oldRef,newRef);
调试时没有得到 ValueChanges 显示以下更改:

Diff:

1.NewObject{globalId:'com.ds.appmanager.services.domain.Application/7'}
2.ObjectRemoved{globalId:'com.ds.appmanager.services.domain.User/5'}
3.ObjectRemoved{globalId: 'com.ds.appmanager.services.domain.Application/3'}
4. ObjectRemoved{globalId:'com.ds.appmanager.services.domain.User/6'}
5. ObjectRemoved{globalId:'com.ds.appmanager .services.domain.User/7'}
6. ReferenceChange{globalId:'com.ds.appmanager.services.domain.User/3', property:'application', oldRef:'com.ds.appmanager.services.domain .Application/3', newRef:'com.ds.appmanager.services.domain.Application/7'}

4

0 回答 0