Search code examples
javajavers

Javers: restore previous version of bean


is it possible to "checkout" a specific commit or version/snapshot of an object? I mean: I done some changes on my bean, then committed the object through Javers utilities, but I want to checkout a previous version because actual version is corrupted or incorrect. Is there a Javers utility to "restore" previous data? Or do I have to restore the object reverting single changes?


Solution

  • Yes, we call it Shadows. Shadows will be released soon in 3.2.0. You can check it out in 3.2.0-RC4:

    For example, to get latest Shadows of "bob" Person, call:

    List<Shadow> shadows =
    javers.findShadows( QueryBuilder.byInstanceId("bob", Person.class).limit(5).build() );
    

    Since Shadows are instances of your domain classes, you can use them directly in your application:

    assert shadows.get(0).get() instanceof Person.class;