Lakshay agarwal
Lakshay agarwal

Reputation: 1

Javers not catching change when a field is changed for an item in a list

I have a list of employees. When any item inside this list is edited and any field is changed for that item then javers is not detecting the change.

class Company {
String companyName;
List<employee> employees;
...
}

class employee {
String name;
int age;
}

I'm trying to build by jqlQuery in the following way -

jqlQuery = QueryBuilder.byInstanceId(id, Company.class)
    .withShadowScope(ShadowScope.DEEP_PLUS)
    .withChangedPropertyIn(Arrays.stream(fields).map(Field::getName).toArray(String[]::new))
    .build();
List<Shadow> shadows = javers.findShadows(jqlQuery);

where, fields is an array which contains elements for which I want to capture change. (This includes the List employees)

What should be modified so that if I change the age of suppose any one employee inside the list of employees, then javers can catch this change?

I tried changing the shadow scope to build the jql query so that a change in any list element is also caught by javers but it didn't seem to work

Upvotes: 0

Views: 46

Answers (1)

user2520280
user2520280

Reputation: 1

Changes to the properties within employee are not going to show under the Company object. The only changes you'll see in Javers related to the company.employees property is the addition or removal of an employee to the list. Changes to the employee itself will be audited as part of the employee.

To see the changes that have been made to the employees you can run this:

Changes changes = javers.findChanges(QueryBuilder.byClass(Employee.class).build())

println changes.prettyPrint()

Upvotes: 0

Related Questions