Search code examples
spring-bootjavers

Fetching parent changes with children changes in single query


I use javers-spring-boot-starter-sql, version 5.11.1.

Fetching changes for parent entity:

QueryBuilder jqlQuery = QueryBuilder.byInstanceId(23702, CoalAgreement.class).withNewObjectChanges().withChildValueObjects();
Changes changes = javers.findChanges(jqlQuery.build());

It returns changes that only contains information about adding PriceList to collection:

Commit 1.00 done by admin at 04 sie 2020, 15:19:28 :
* new object: CoalAgreement/23702
* changes on CoalAgreement/23702 :
  - 'priceLists' collection changes :
    0. '...PriceList/43853' added

The problem is I also would like to know changes in child collection of PriceList. The only way I found is to manually fetch PriceList changes:

Changes changes = javers.findChanges(QueryBuilder.byInstanceId(43853,PriceList.class).build());

Is there any way to fetch parent together with children collections changes?


Solution

  • Currently, the only way to eager load whole object graphs is using Shadow Queries.

    In a Shadow Query, you can specify eager loading scope. There are four scopes. The wider the scope, the more object shadows are loaded to the resulting graph (and the more database queries are executed).

    see https://javers.org/documentation/jql-examples/#query-for-shadows