How to track changes with Envers so on child update the current version of the parent is linked to the current version of the child with the changes?

Viewed 183

Let's say we have an versioned entity Book. The book has a property which is also a versioned entity Author.

Author author = new Author();
author.setName("foo");
save(author);


Book book = new Book();
book.setAuthor(author);
save(book);

Now if I change the author's name eg

author.setName("bar");

I want "bar" to be seen from the version of Book as of this hour. eg

Book book = getRevForHour(Book.class, LocalDateTime.now());

if (book.getAuthor().getName() == "bar") {
    System.out.println("got what I wanted");
} else {
    System.out.println("didn't get what I wanted");
}

But right now I'm getting "foo" which is the value the Author had as of the last rev creation for Book.

Is there a way to trigger a cascade of rev creations upwards to all entities? Or is there a better way to get such historic data?

edit:

I ended up adding a column "last_update" to all entities and entirely manually ended up propagating changes upwards whenever an entity was altered. Changing the value in lastUpdate then triggered envers to create a new version.

0 Answers
Related