首页 > 解决方案 > Javers findshadows 在子对象和父对象的某些字段中返回 null

问题描述

我有以下两个域对象,它们之间有一对多的关系 1.BOY (Boy.java) 2.CYCLE (cycle.java) 它是一个基于 springboot 的应用程序,我用这个应用程序做了 javerse 存储库实现。

在使用 JQL [javerse 查询语言] 获取阴影时,它无法正常工作

1.Pom文件我添加了javers-spring-boot-starter-sql依赖

2.男孩实体类

@Entity
@Table(name = "boy")
public class Boy implements Serializable {

private static final long serialVersionUID = 1L;

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
@SequenceGenerator(name = "sequenceGenerator")
private Long id;

@Column(name = "name")
private String name;

@OneToMany(mappedBy = "boy")
private Set<Cycle> cycles = new HashSet<>();
}

3.循环实体类

@Entity
@Table(name = "cycle")
public class Cycle implements Serializable {

private static final long serialVersionUID = 1L;

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
@SequenceGenerator(name = "sequenceGenerator")
private Long id;

@Column(name = "cycname")
private String cycname;

@ManyToOne
@JsonIgnoreProperties("cycles")
private Boy boy;
}

4.Boy 和 Cycle 存储库已使用 @JaversSpringDataAuditable 进行注释

6.使用 Javerse 查询语言审核 Fetch API

    @PostMapping("/audit/shadowsboy/{id}")
    @Timed
    public String getShadows(@PathVariable Long id) {


        JqlQuery queryBuilder = QueryBuilder.byInstanceId(id, Boy.class).withScopeCommitDeep().build();
        List<Shadow<Object>> shadowList = javers.findShadows(queryBuilder);
        System.out.println("shadows: ::::::::::::::::::::::::::" + javers.getJsonConverter().toJson(shadowList));

        return javers.getJsonConverter().toJson(shadowList);
    }

输出:给男孩添加一个循环后,按男孩 id 查找阴影返回

{
"commitMetadata": {
"author": "anonymousUser",
"properties": [],
"commitDate": "2019-07-20T13:11:24.076",
"commitDateInstant": "2019-07-20T07:41:24.076Z",
"id": 2.00
},
"it": {
"id": 951,
"name": null,
"cycles": []
}
},
{
"commitMetadata": {
"author": "anonymousUser",
"properties": [],
"commitDate": "2019-07-20T13:04:26.988",
"commitDateInstant": "2019-07-20T07:34:26.988Z",
"id": 1.00
},
"it": {
"id": 951,
"name": "gajendran.g",
"cycles": []
}
}
]

预期结果:cycles 对象不能为空或 null

标签: javers

解决方案


推荐阅读