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:
- Trigger: one possibility is to define triggers on the tables, cons of this way is dependency to a database.
- Hibernate Envers: this solution is good but makes my DAO layer depend on Hibernate and I won't have the benefit of JPA and its provider independency.
- Spring Data Commons + hades: is good but added some column to any entity by
MappedSuperClass
annotation like:Create User
,Create Date
,Last Update User
andLast Update Date
. It means storing the complete history and state of a entity. - My own design/implementation:* I could implement a layer for this goal but I don't like this solution because I think this requirement isn't special for me and I think it's been solved by other people following best practices (I shouldn't reinvent the wheel)
Does anyone have any suggestions or solutions for this problem?
(sorry if my question is long and maybe be too basic for experts)