img
In this section, we will demonstrate the validity audit strategy. Although it will trigger more database
updates, retrieving the history records becomes much faster. Because the end revision timestamp is also
written to the history records, it will be easier to identify the image of a record at a specific point of time
when querying the data.
Adding Hibernate Envers Dependencies
We need to add the Maven dependency listed in Table 10-4 to our project.
Table 10-4. Hibernate Envers Dependencies
Group ID
Artifact ID
Version
Description
3.6.8.Final
Hibernate Envers module library
org.hibernate
hibernate-envers
Adding Tables for Entity Versioning
To support entity versioning, we need to add a few tables. First, for each table that the entity (in this
case, it's the ContactAudit entity class) will be versioning, we need to create the corresponding history
table. For the versioning of records in the CONTACT_AUDIT table, let's create a history table called
CONTACT_AUDIT_H. Listing 10-46 shows the table creation script (schema.sql).
Listing 10-46. The CONTACT_AUDIT_H Table
CREATE TABLE CONTACT_AUDIT_H (
ID INT NOT NULL
, FIRST_NAME VARCHAR(60) NOT NULL
, LAST_NAME VARCHAR(40) NOT NULL
, BIRTH_DATE DATE
, VERSION INT NOT NULL DEFAULT 0
, CREATED_BY VARCHAR(20)
, CREATED_DATE TIMESTAMP
, LAST_MODIFIED_BY VARCHAR(20)
, LAST_MODIFIED_DATE TIMESTAMP
, AUDIT_REVISION INT NOT NULL
, ACTION_TYPE INT
, AUDIT_REVISION_END INT
, AUDIT_REVISION_END_TS TIMESTAMP
, UNIQUE UQ_CONTACT_AUDIT_H_1 (FIRST_NAME, LAST_NAME)
, PRIMARY KEY (ID, AUDIT_REVISION)
);
To support the validity audit strategy, we need to add four columns for each history table (the bold
columns in Listing 10-46). Table 10-5 shows the columns and their purposes.
Search WWH :
Custom Search
Previous Page
Spring Framework 3 Topic Index
Next Page
Spring Framework 3 Bookmarks
Home