I have a set of domain objects and its related tables for application's configurations. Authenticated users can change these domain objects data thru a presentation layer. These domain objects have very important data and I need find who and when changed their data. My application's data access layer is implemented using JPA, Hibernate and Spring. I need to have a record of every change, consisting of: User + Action Date + Action Type + previous values.
For example, let's consider a trivial domain object (simplified for the purpose of this question):
@Entity
class Connection
{
private Long id;
private String name;
private String protocol;
}
Assume there is a Connection
instance with the following values:
Connection
id = 1;
name = Web;
protocol = HTTPS;
After a user (eg John
) logins in UI and changes this connection to the following values:
Connection
id = 1;
name = Web;
protocol = HTTP;
As you can see, John changes protocol from HTTPS
to HTTP
(a secure protocol to insecure!), as a result I need to save the history of Connection
instances in another table for auditability.
I've researched for a solution for me and found following result:
MappedSuperClass
annotation like: Create User
, Create Date
, Last Update User
and Last Update Date
. It means storing the complete history and state of a entity.Does anyone have any suggestions or solutions for this problem?
(sorry if my question is long and maybe be too basic for experts)
I've worked with many systems where we add extra columns to the database tables to track user ID and timestamp for audit purposes.
If you need to keep track of the previous values you can use date ranges to tell when the data was valid. For example:
from 01.01.2012 to 31.12.2012 the protocol was HTTPS from 01.01.2013 to 'forever' the protocol was HTTP
For more on patterns of time see Martin Fowler's blog.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With