javers - 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
解决方案
推荐阅读
- excel - 勾选时获取复选框的单元格地址
- python - 在构建 Kivy 应用程序“未安装 sdkmanager”时
- asp.net-mvc - MVC 验证复选框
- aws-lambda - 部署为 Docker 映像时如何运行多个 lambda 函数?
- jquery - 另一个范围内的 AlpineJS select2 组件引发错误
- matlab - 我可以在 MATLAB 中并行运行两个独立的 while 循环吗?
- javascript - iframe 中的 gtag 子域
- python - 我正在运行下面的代码。但我无法运行 Sentiment_score (df) 代码
- forms - Flutter - 如何创建此注册表单?
- javascript - Firestore 云不会保存所有用户的数据 (js)