Search code examples
javers

How to query for a snapshot by field that had a specific value?


The following query returns changes to Subscription entities whose status field changed within the date range.

 QueryBuilder.byClass(Subscription.class)
             .from(LocalDate.of(2017, 11, 1))
             .to(LocalDate.of(2017, 12, 1))
             .withChangedProperty("status")

How can I write a query that finds historical versions of Subscription that had a certain status on a given date? I'm not looking for changes to status, but just want to find the snapshot of the entities who had a particular status on a given date.

Something like:

javers.findSnapshots(
     QueryBuilder.byClass(Subscription.class)
                 .on(LocalDate.of(2017, 11, 1))
                 .withProperty("status", "TRIAL"))

This would return snapshots of Subscription where the status property was equal to TRIAL for the last commit starting from 2017-11-01 backwards.


Solution

  • For now, there is no such option, we have the open issue for that, see https://github.com/javers/javers/issues/556