Search code examples
javaspring-bootjavers

Javers SpringBoot integration QueryBuilder byInstanceId returns empty result


I'm using springboot integration from this example:

https://github.com/l7777777b/organization-structure

It's my forked example from:

https://github.com/javers/organization-structure

using mysql and recent version of Javers 5.6.3, gradle 5.4.1 and springboot 2.1.6.RELEASE.

First im not sure if its an expected behaviour, but the changes and snapshot return empty result when using QueryBuilder.byInstanceId , but when using QueryBuilder.byClass it shows correctly.

QueryBuilder.byInstanceId can show results for newly inserted data, for existing data (data already on database prior the service started) it seems not getting fetched.

To reproduce it:

  1. run the service like usual ./gradlew organization-structure-sql:bootRun
  2. create new person

     POST http://localhost:8080/view/person
     {
         "id": 1,
         "firstName": "Yang",
         "lastName": "Huajie",
         "sex": "MALE",
         "salary": 22,
         "position": "DEVELOPER"
     }
    
  3. update it, change any property

  4. get snapshots using this code:

     QueryBuilder jqlQuery = QueryBuilder.byInstanceId("1", Person.class);
     List<CdoSnapshot> changes = javers.findSnapshots(jqlQuery.build());
     JsonConverter jsonConverter = javers.getJsonConverter();
     System.out.println(jsonConverter.toJson(changes));
    
  5. it should be showing some data, then restart the service. or force stop it and run number 1.
  6. get the same snapshots again by running number 4, and it should be showing empty result. unless i insert new data, the newly inserted data will be returned.

But if i change QueryBuilder.byInstanceId(personId, Person.class); into QueryBuilder.byClass(Person.class); i can get all result from database correctly, but i only need to search specific id that's why i need to use byInstanceId.


Solution

  • Its look like id is Integer and you are passing a String value to the byInstanceId("1"), could you please try to change it to int and check ex. byInstanceId(1)