1

I need to maintain history of modifications to data in my database. The modifications will not be very common so it seems OK to store the entire row instead of just diffs which would be more efficient in terms of space. Hibernate envers seems like a decent solution.

Now I notice that Audit table is more like a shadow table which will store the data on the first insert itself. Is it possible to prevent envers from storing the audit information until the first update is made. I just want to reduce the disk footprint of database since I may not be running on a very high performance server. I want the actual table to contain the most recent data and the Audit table to contain historical data only not the current row. I am not using any specific configuration in my persistence.xml. Hibernate 4.1 seems to find the classes for Auditing with annotations. I think I should be dealing with the post insert listeners but not sure exactly what I should do with it.

Rohit Banga
  • 18,458
  • 31
  • 113
  • 191
  • did you figure out a way to do this? I am trying to achieve something similar, but I don't want to save any data, I just want to know when an entity was created/modified/deleted. Appreciate if you can share your experiences. – Vikram Jul 31 '13 at 22:22
  • No I did not ... for the time being i decided to live with this limitation. Some links that may be helpful to you: http://stackoverflow.com/questions/12800540/hibernate-envers-how-to-store-only-updated-values – Rohit Banga Aug 01 '13 at 02:44
  • http://docs.jboss.org/hibernate/core/4.0/devguide/en-US/html/ch15.html#d0e5519 – Rohit Banga Aug 01 '13 at 02:45
  • @Vikram if you find an answer please answer this question ... could be helpful to someone else who comes here looking for the same. – Rohit Banga Aug 03 '13 at 01:52
  • Firstly I apologize for the delayed response. Sure for now we wrote a simple auditing framework ourselves as we thought we wont be needing the complete rich feature set of envers. But if in the future envers supports ignoring revision data storage, I will definitely post the solution here. As of now, this feature has not been implemented in envers yet. – Vikram Oct 03 '13 at 16:47

1 Answers1

0

This has been requested before and while would perhaps be a nice feature, its definitely one which doesn't have its own source of issues.

Understand that Envers ships with 2 audit strategies: Default and Validity.

The DefaultAuditStrategy is a very basic strategy which has no expectation that any previous revision row exists in the audit table. This particular strategy would likely easily work with a case where only the changed rows were stored.

But unfortunately the other strategy wouldn't.

The ValidityAuditStrategy expects that when a change is detected a previous audit row exists to manipulate the validity strategy columns. If the audit table doesn't store the inserts, then the very first change would fail because the strategy would determine that it could not manipulate the strategy fields correctly.

This perhaps may change at some future point, but as of now we don't support such a case.

Naros
  • 19,928
  • 3
  • 41
  • 71