I want to track the changes made to every column in a particular table. I thought of storing the changes in another table with the following columns: id, field, and data where field (string value) is the column in the target table that has been altered and data is the new value of that field.
When returning the data set, I thought of retrieving the original data from the target table and the changed values from the table tracking changes, then using java’s reflection capabilities to set the changed fields’ values to the newest changed value.
Based on the above I have the following questions:
- Does my approach makes sense? Is there a better way to achieve the desired results?
- I’m using JPA 2 to handle ORM, are there any ORM features that can be helpful in achieving the end goal?
Thanks
Check Hibernate envers and Eclipselink historical session for entity auditing..
JPA 2.0 spec does not have anything related to entity auditing..