Reputation: 3102
We are currently using JaVers 3.0.0. Suppose we have the following two entities A and B. And A keeps track of some Bs in a list.
@Entity
@TypeName("A")
public class A {
@Id
private int id;
private List<B> items;
public A() {
items = new ArrayList<>();
}
public A(int id) {
this();
this.id = id;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public List<B> getItems() {
return items;
}
public void setItems(List<B> items) {
this.items = items;
}
}
And here is our rather simple class B.
@Entity
@TypeName("B")
public class B {
@Id
private int id;
public B() {
}
public B(int id) {
this.id = id;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
}
Lets commit three changes to an object of type A:
After that I want to observe changes on B.
Javers javers = JaversBuilder
.javers()
.build();
A a = new A(1);
javers.commit("[email protected]", a);
a.getItems().add(new B(1));
a.getItems().add(new B(2));
javers.commit("[email protected]", a);
a.getItems().remove(0);
javers.commit("[email protected]", a);
List<Change> changes = javers.findChanges(
QueryBuilder.byClass(B.class)
.build());
String changelog = javers.processChangeList(changes, new SimpleTextChangeLog());
System.out.println(changelog);
The output says zero changes. I was expecting to see a removed object since B is an entity and has an Id. What am I missing?
Edit Thanks for answering in the comments so far. Maybe I wasn't detailed enough. Sorry about that.
What I am trying to query is all the changes on A and all the changes on B. I only commit A, but maybe that is the problem? Should I track A and B?
Upvotes: 0
Views: 919
Reputation: 3496
javers.compare()
and javers.commit()
don't work in the same way.
compare()
simply compares two object graphs, without any context.
That's why you could expect ObjectRemoved
on the change list when comparing graphs.
But commit()
is for auditing changes.
Since you've mapped both classes as Entities, they are independent. B objects can't be marked as deleted just because they are no longer referenced by A objects.
The only way to mark them as deleted (and to have ObjectRemoved change) is by calling commitShallowDelete()
Upvotes: 1