0

I have integrated hibernate envers in spring boot. Now my requirement is to have old value also for the particular column when value changed in *_AUD tables. However I cant see any feature available in Hibernate Envers plugin. Please suggest.

Thanks

  • Why? Envers stores the previous snapshot, so you can compare the previous record and the next to get the changes. What you want is simply not how envers works. – M. Deinum Jun 04 '20 at 17:14

1 Answers1

0

Unfortunately what you are looking to do just isn't someting supported.

It's one thing to think of an entity and needing to store basic type values such as strings or numeric data and have its old/new value represented by two columns in the audit table; however when you move beyond basic entity mappings to ones where you have relationships between entity types or collections; you begin to see that trying to store old/new data in the same row just isn't efficient and in some cases feasible.

That said, you can still read the audit history and deduce these old/new values using a variety of ways that include the Envers Query API, Debezium, or even basic database triggers.

Naros
  • 19,928
  • 3
  • 41
  • 71
  • Thanks for the response. I am planning to use native queries to get all revisions of particular entity primary key in descending order of revid and then in java I am trying to compare N And N+1 rows to get old and new values of columns. Do you think is it fine or any better alternative to achieve the results? – Nikhil Jain Jun 04 '20 at 15:38
  • I would suggest you take a look at the `AuditReader` API instead. This provides you with an easy to use, fluent audit query interface to fetch the data in exactly the fashion you describe. It's heavily modeled off the legacy Hibernate Criteria API. This interface knows how to interpret the audit table relationships without you having to deduce that yourself. – Naros Jun 04 '20 at 16:16