- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想使用 JaVers 来跟踪我的 Java 对象的更改。基本示例工作正常,但我无法让它检测存储在集合中的对象的更改。
如果我延长 ChangeLogExample.class改变的例子下属之一:
public static void main(String[] args) {
Javers javers = JaversBuilder.javers().build();
Employee bob = new Employee("Bob", 9_000, "Scrum master" );
javers.commit("hr.manager", bob);
// do some changes and commit
bob.setPosition("Team Lead");
bob.setSalary(11_000);
javers.commit("hr.director", bob);
bob.addSubordinates(new Employee("Trainee One"), new Employee("Trainee Two"));
javers.commit("hr.manager", bob);
bob.getSubordinates().get(0).setAge(42); // <<<< This is the change I want to detect
javers.commit("hr.manager", bob);
// when:
List<Change> changes = javers.findChanges(
QueryBuilder.byInstanceId("Bob", Employee.class).withChildValueObjects().build());
String changeLog = javers.processChangeList(changes, new SimpleTextChangeLog());
// then:
System.out.println(changeLog);
}
这是打印的变更日志:
commit 3.0, author: hr.manager, 2017-06-06 11:17:17
changed object: Employee/Bob
list changed on 'subordinates' property: [(0).added:'Employee/Trainee One', (1).added:'Employee/Trainee Two']
commit 2.0, author: hr.director, 2017-06-06 11:17:17
changed object: Employee/Bob
value changed on 'position' property: 'Scrum master' -> 'Team Lead'
value changed on 'salary' property: '9000' -> '11000'
因此对第一个下属年龄的更改不会显示在变更日志中。
使用withChildValueObjects()
没有什么区别。
当我单独将更改提交到 Employee 实例时,我得到了对受训者年龄的更改,但这不是我所期望的(也不是我想要的)。
所以我的问题是:如何让年龄的更改显示在 ChangeLog 中?
<小时/>我使用的是 JaVers 3.2.0
Employee
类与 JaVers 示例中没有变化:https://github.com/javers/javers/tree/master/javers-core/src/test/java/org/javers/core/examples/model
main()
方法只是 https://github.com/javers/javers/blob/master/javers-core/src/test/java/org/javers/core/examples/ChangeLogExample.java 中的测试
最佳答案
好的,这里有一些问题。首先,Empolyee
对象被映射为Entities
。所以在 JaVers 中,没有他们之间的父/子关系(实际上任何类型的关系)。这就是为什么 withChildValueObjects()
过滤器在这里不适用。它仅适用于 Entities
拥有的 ValueObjects
,请参阅 http://javers.org/documentation/jql-examples/#child-value-objects-filter
不过,有两种方法可以改进您的查询。
直接询问您要跟踪的实体实例。
将新的 Shadow API 与查询范围结合使用,请参阅 http://javers.org/documentation/jql-examples/#query-for-shadows这是一个新功能,并且会在功能上进行改进。如果查询将选择两个实体的快照,您就可以使用它了。
参见下面的代码:
def "should ... "(){
given:
Javers javers = JaversBuilder.javers().build()
Employee bob = new Employee("Bob", 9_000, "Scrum master" )
javers.commit("hr.manager", bob)
// do some changes and commit
bob.setPosition("Team Lead")
bob.setSalary(11_000)
javers.commit("hr.director", bob)
bob.addSubordinates(new Employee("Trainee One"), new Employee("Trainee Two"))
javers.commit("hr.manager", bob)
bob.getSubordinates().get(0).setAge(42) // <<<< This is the change I want to detect
bob.salary++ // !
javers.commit("hr.manager", bob)
when: "ask for the the right Entity instance"
List changes = javers.findChanges(
QueryBuilder.byInstanceId("Trainee One", Employee.class).build())
then:
println( javers.processChangeList(changes, new SimpleTextChangeLog()) )
true
when: "use the new Shadows"
List shadows = javers.findShadows(
QueryBuilder.byInstanceId("Bob", Employee.class)
.withShadowScopeDeep().build())
then:
shadows.each {
assert it.get() instanceof Employee
}
Employee lastBobShadow = shadows[0].get()
assert shadows[0].commitMetadata.id.majorId == 4
assert lastBobShadow.subordinates[0].name == "Trainee One"
assert lastBobShadow.subordinates[0].age == 42
}
关于java - JaVers 未检测到集合内对象属性的更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44386270/
我将 Javers 与 Spring Data JPA + Hibernate 结合使用。当我使用 CurdRepository.save(Collection) 时,Javers API 正在逐个审
我正在使用 Spring Data REST 开发 RESTful API。现在,对于审核,Spring 确实可以选择审核元数据,例如 created_date 和 modified_date,但它们
我收到以下错误:并且我正在使用 Spring Boot Mongo Javers。 java.lang.IllegalStateException: Failed to execute Command
我正在努力了解为什么以下内容没有给我相同的结果。 如果我使用 Javers 来比较两个列表(它们具有不同顺序的项目),那么我没有发现任何差异,因为我指定了 AS_SET 列表比较来忽略列表中项目的顺序
作为测试的一部分,我正在尝试比较两个 json,预期的和使用 Javers 的 API 响应。我希望比较排除响应动态生成的 ID 参数。 我的旁白是这样的 public class expectedR
问题陈述 我正在试验 Javers 3.5.1 报告已提交更改的能力。看来只有当变化是原始变化时才会被报告;当实体层次结构中的对象引用发生更改时,不会报告更改。 示例 这是一个示例: Jave
Javers 默认情况下会创建一个提交,对要记录的对象进行深度遍历。当您有非常复杂的对象,并且具有从父类等继承的属性时,必须遍历整个图表并注释您不想记录的每个属性可能会很痛苦。 有没有办法默认指定 J
Javers 通过什么方式审核自定义“删除”?使用 spring-boot 集成,例如: @Transactional @Modifying @Query(" delete from ExecuteP
目前,Javers 在提交元数据中记录审计的用户名和时间戳,但我也想存储用户 ID。是否可以向 Javers 提交元数据添加更多字段,例如用户 ID 或 IP 地址? 最佳答案 是的,提交属性。它是字
我有一个 Java 8/Maven/Spring Boot 项目。我正在使用 Javers 来审核应用程序中的更改,但是我创建了一个自定义注释,该注释放置在我希望在更改时进行审核的类中的字段上方。这是
我正在为我们的应用程序设置一个审计系统。表格增长得非常快。所以我想知道,是否有一种机制可以在一段时间后清理快照和提交,例如所有超过 30 天的快照。如果不可能,您能否建议其他方法?谢谢。 最佳答案 我
我有与 https://github.com/javers/javers/issues/98 中描述的类似用例. 在下面的代码中,当我更新依赖对象并提交 Employee bob 时,我希望更改依赖项
我想使用 JaVers 来跟踪我的 Java 对象的更改。基本示例工作正常,但我无法让它检测存储在集合中的对象的更改。 如果我延长 ChangeLogExample.class改变的例子下属之一: p
我有两个具有相同数据但顺序不同的列表。 为什么 Javers compareCollections 方法会看到 Levenshtein 距离发生两个变化(一个 ValueRemoved 和一个 Val
以下测试失败 @Test public void test() { Javers javers = javers().build(); Model anObject = new
我正在尝试实现 Javers 来审核我相当复杂的对象,到目前为止我很喜欢它。但是当我看到数据库时,整个快照都会为我的对象保存,最终会在我的用例中变得庞大。由于我只使用 Javers 来审核更改,而不是
我在一个由 10-20 个团队组成的环境中工作。每个团队在单个数据库模式中都有自己的一组数据库表。所有团队都将 Java Spring Boot 应用程序与 JaVers 一起使用。我的任务是为我们的
是否可以“ checkout ”对象的特定提交或版本/快照?我的意思是:我对我的 bean 进行了一些更改,然后通过 Javers 实用程序提交了对象,但我想 checkout 以前的版本,因为实际版
我正在尝试使用 JaVers 存储来 self 无法更改的第 3 方库的对象。对象定义类似于: interface TheirObject extends WithId{ //Other p
嗨,我是 Javers 的新手。 我有一个 Entity ,我正在为其实现一个自定义比较器,以便使用 Javers 进行比较。 我的实体:- 包 com.devyansh.entity; 导入java
我是一名优秀的程序员,十分优秀!